Urlretrieve and User-Agent? - Python
I'm using urlretrieve from the urllib module. I cannot seem to find how to add a User-Agent description to my requests. Is it possible with urlretrieve? or do I need to use another method? First, set version: urllib.URLopener.version = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36 SE 2.X MetaSr 1.0' Then: filename, headers = urllib.urlretrieve(url) d.rey You can use URLopener or FancyURLopener classes. The 'version' argument specifies the user agent of the opener object. opener = FancyURLopener({}) opener.version = 'Mozilla/5.0 (Windows