I want to set requests 'user-agent' header globally. But I can't find any way to do it. Can anyone help me?
You can also monkey-patch default_user_agent, like this:
from requests import utils
DEFAULT_USER_AGENT = 'My Agent'
utils.default_user_agent = lambda: DEFAULT_USER_AGENT
This method is useful when the requests are made from an external package, and you don't want to modify the package's source code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With