How can I download a webpage with a user agent other than the default one on urllib2.urlopen?
urllib2.urlopen is not available in Python 3.x; the 3.x equivalent is urllib.request.urlopen. See Changing User Agent in Python 3 for urrlib.request.urlopen to set the user agent in 3.x with the standard library HTTP facilities.
Setting the User-Agent from everyone’s favorite Dive Into Python.
The short story: You can use Request.add_header to do this.
You can also pass the headers as a dictionary when creating the Request itself, as the docs note: