Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to set/add to user agent string? #84

Closed
hmpf opened this issue Dec 5, 2019 · 7 comments
Closed

Any way to set/add to user agent string? #84

hmpf opened this issue Dec 5, 2019 · 7 comments
Milestone

Comments

@hmpf
Copy link

hmpf commented Dec 5, 2019

I know mailto can be set, but I hope to use this library as part of a service that fetches from many APIs and would like the same or same-ish user agent everywhere.

@sckott sckott added the question label Dec 5, 2019
@sckott
Copy link
Owner

sckott commented Dec 5, 2019

thanks for your question @hmpf

we currently send with each request the following UA headers (package versions change obviously)

User-Agent: python-requests/2.22.0 habanero/0.7.0
X-USER-AGENT: python-requests/2.22.0 habanero/0.7.0

Would you want to add to that string or change it completely?

@hmpf
Copy link
Author

hmpf commented Dec 6, 2019

Good question. If the existing setting can be both read and changed (allowing changing it completely and adding to it) I think you'll never get this question again :)

I need just to add to the end, my UA, link to site, and a mailto. I'll be hitting crossref once a week or so, is the current plan. (The actual mailto wil lhave to be a setting on my side though as it's a microservice that no doubt will end up running in multiple places.)

@sckott
Copy link
Owner

sckott commented Dec 6, 2019

i'll have a look. Not sure right now what it will look like but it'll be possible for sure

@sckott sckott added this to the v0.8 milestone Dec 9, 2019
@sckott sckott removed the question label Dec 9, 2019
@sckott
Copy link
Owner

sckott commented Dec 10, 2019

@hmpf reinstall from branch user-agent [sudo] pip[3] install git+git://github.com/sckott/habanero.git@caching#egg=habanero

# set an additional user-agent string
x = Crossref(ua_string = "foo bar")
x
x.works(ids = '10.1371/journal.pone.0033693')

## unset the additional user-agent string
x = Crossref()
x.works(ids = '10.1371/journal.pone.0033693')

do verbose logging to see the request headers

import requests
import logging
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True

@hmpf
Copy link
Author

hmpf commented Dec 10, 2019

The pip-url was wrong, this is the correct one: git+git://github.com/sckott/habanero.git@user-agent#egg=habanero.

@hmpf
Copy link
Author

hmpf commented Dec 10, 2019

For python 3, replace import httplib as http_client with import http.client as http_client.

Tested. This covers my needs!

@sckott
Copy link
Owner

sckott commented Dec 11, 2019

woops, thx for the url fix - forgot to fix the copy/paste.

glad it works.

@sckott sckott closed this as completed Dec 11, 2019
@sckott sckott modified the milestones: v0.8, v0.7.2 Dec 11, 2019
sckott added a commit that referenced this issue Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants