Skip to content

Commit 168fb9e

Browse files
authored
Merge pull request #2762 from bsipocz/enh_more_user_agent
ENH: adding more info to User-Agent
2 parents c3c0a1a + 6ad1b20 commit 168fb9e

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ Infrastructure, Utility and Other Changes and Additions
269269
- New function, ``utils.cleanup_downloads.cleanup_saved_downloads``, is
270270
added to help the testcleanup narrative in narrative documentations. [#2384]
271271

272+
- Adding more system information to User-Agent. [#2762]
273+
272274
- Removal of the non-functional ``nrao`` module as it was completely
273275
incompatible with the refactored upstream API. [#2546]
274276

astroquery/mast/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
import requests
1212
import json
13+
import platform
1314
from urllib import parse
15+
1416
import astropy.coordinates as coord
1517

1618
from ..version import version
@@ -74,7 +76,8 @@ def _simple_request(url, params):
7476
"""
7577

7678
session = requests.session()
77-
headers = {"User-Agent": "astroquery/{} {}".format(version, session.headers['User-Agent']),
79+
headers = {"User-Agent": (f"astroquery/{version} Python/{platform.python_version()} ({platform.system()}) "
80+
f"{session.headers['User-Agent']}"),
7881
"Content-type": "application/x-www-form-urlencoded",
7982
"Accept": "text/plain"}
8083

astroquery/query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import keyring
99
import io
1010
import os
11+
import platform
1112
import requests
1213
import textwrap
1314

@@ -184,9 +185,8 @@ def __init__(self):
184185
S = self._session = requests.Session()
185186
self._session.hooks['response'].append(self._response_hook)
186187
S.headers['User-Agent'] = (
187-
'astroquery/{vers} {olduseragent}'
188-
.format(vers=version.version,
189-
olduseragent=S.headers['User-Agent']))
188+
f"astroquery/{version.version} Python/{platform.python_version()} ({platform.system()}) "
189+
f"{S.headers['User-Agent']}")
190190

191191
self.name = self.__class__.__name__.split("Class")[0]
192192
self._cache_location = None

astroquery/utils/tap/conn/tapconn.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
1616
"""
1717

18-
try:
19-
# python 3
20-
import http.client as httplib
21-
except ImportError:
22-
# python 2
23-
import httplib
18+
import http.client as httplib
2419
import mimetypes
20+
import platform
2521
import time
22+
2623
from astroquery.utils.tap.xmlparser import utils
2724
from astroquery.utils.tap import taputils
2825
from astroquery import version
@@ -122,7 +119,8 @@ def __interna_init(self):
122119
self.__postHeaders = {
123120
"Content-type": CONTENT_TYPE_POST_DEFAULT,
124121
"Accept": "text/plain",
125-
"User-Agent": "astroquery/{vers}".format(vers=version.version),
122+
"User-Agent": "astroquery/{vers} Python/{sysver} ({plat})".format(
123+
vers=version.version, plat=platform.system(), sysver=platform.python_version()),
126124
}
127125
self.__getHeaders = {}
128126
self.__cookie = None

0 commit comments

Comments
 (0)