Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set requests 'user-agent' header globally

I want to set requests 'user-agent' header globally. But I can't find any way to do it. Can anyone help me?

like image 709
白稳平 Avatar asked Sep 25 '18 12:09

白稳平


1 Answers

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.

like image 113
Dylan Tack Avatar answered Sep 24 '22 19:09

Dylan Tack