astropy / pyvo

An Astropy affiliated package providing access to remote data and services of the Virtual Observatory (VO) using Python.
https://pyvo.readthedocs.io/en/latest
BSD 3-Clause "New" or "Revised" License
75 stars 52 forks source link

pyvo user agent in case of authenticated queries #263

Open almicol opened 3 years ago

almicol commented 3 years ago

The user agent reported by pyvo v1.1 when performing an anonymous TAP query is:

python-pyvo/1.1

while instead when I perform an authenticated query the user agent is set to:

python-requests/2.25.1

It is a pity to lose the pyvo information, the user agent statistics I derive are therefore affected.

My code, with authentication, looks like this:

mysession = requests.Session()
mysession.headers['Authorization'] = "Bearer " + mytoken
tap = vo.dal.TAPService(TAPURL, session=mysession)
query = 'select table_name from TAP_SCHEMA.tables'
tables = tap.search(query)

It would seem useful if the user agent set by the python requests library could be overwritten by pyvo. But I'd consider this very low priority, it is just for you to know...

andamian commented 3 years ago

Hmm. We need to look into this. Thanks @almicol

andamian commented 2 years ago

@almicol - finally had a chance to look at this. The thing is that you are creating the session yourself so you "own" it in this case. pyvo could set it but NOT if the session is part of an application that wants to set its own user agent. Maybe pyvo could set it ONLY if it's not set already? Not sure about that either.

If you want to create a pyvo session you could use pyvo.utils.http.get_session() and that session has the pyvo user agent set. It is however a bit buried 3 levels deep and not documented. Maybe we should bring it a bit forward (i.e. expose it directly in pyvo.utils?