From 66d643d58544997511bab15891aa43c91820ec98 Mon Sep 17 00:00:00 2001 From: Stefaan Lippens Date: Wed, 29 Jan 2020 14:56:45 +0100 Subject: [PATCH] Add python version and platform to user agent header --- openeo/rest/connection.py | 7 ++++++- tests/rest/test_connection.py | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/openeo/rest/connection.py b/openeo/rest/connection.py index 59fd62934..83195155c 100644 --- a/openeo/rest/connection.py +++ b/openeo/rest/connection.py @@ -5,6 +5,7 @@ import logging import pathlib import shutil +import sys import warnings from typing import Dict, List from urllib.parse import urljoin @@ -55,7 +56,11 @@ def __init__(self, root_url: str, auth: AuthBase = None, session: requests.Sessi self.session = session or requests.Session() self.auth = auth or NullAuth() self.default_headers = { - "User-Agent": "openeo-python-client/{v}".format(v=openeo.client_version()) + "User-Agent": "openeo-python-client/{cv} {py}/{pv} {pl}".format( + cv=openeo.client_version(), + py=sys.implementation.name, pv=".".join(map(str,sys.version_info[:3])), + pl=sys.platform + ) } def build_url(self, path: str): diff --git a/tests/rest/test_connection.py b/tests/rest/test_connection.py index b5c570b38..bd9d6148f 100644 --- a/tests/rest/test_connection.py +++ b/tests/rest/test_connection.py @@ -1,9 +1,10 @@ +import re import unittest.mock as mock import pytest import requests_mock -from openeo.rest import OpenEoClientException +from openeo.rest import OpenEoClientException from openeo.rest.auth.auth import NullAuth, BearerAuth from openeo.rest.connection import Connection, RestApiConnection, connect, OpenEoApiError @@ -40,7 +41,11 @@ def test_rest_api_headers(): conn = RestApiConnection(API_URL) with requests_mock.Mocker() as m: def text(request, context): - assert request.headers["User-Agent"].startswith("openeo-python-client") + assert re.match( + r"^openeo-python-client/[0-9a-z.-]+ .*python/3.* (linux|win|darwin)", + request.headers["User-Agent"], + re.I + ) assert request.headers["X-Openeo-Bar"] == "XY123" m.get("/foo", text=text)