Jul-14-2017, 05:36 PM
https://github.com/python/cpython/blob/2...b2.py#L336 Wrote:class OpenerDirector: def __init__(self): client_version = "Python-urllib/%s" % __version__ self.addheaders = [('User-agent', client_version)]
So the default opener for urllib always includes the user agent, at init. So there's no option to disable it... but you can just create an opener and clear that header out of it. Something like this?
import urllib2 opener = urllib2.build_opener() opener.addheaders = [header for header in opener.addheaders if header[0] != "User-agent"] urllib2.install_opener(opener) # now you can use urllib2.open() normally, without the useragent header data = urllib2.open("https://python-forum.io")