pyvo icon indicating copy to clipboard operation
pyvo copied to clipboard

pyvo user agent in case of authenticated queries

Open almicol opened this issue 3 years ago • 2 comments

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...

almicol avatar May 14 '21 12:05 almicol

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

andamian avatar May 18 '21 18:05 andamian

@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?

andamian avatar Oct 29 '21 01:10 andamian