urllib user agent?

Nelson Minar nelson at monkey.org
Sun May 9 11:42:51 EDT 2004


Michael <mogmios at mlug.missouri.edu> writes:

> How do you change the user agent reported by urllib? I need to access
> a resource that rejects anything but IE.

Here's how I do it in urllib2:
  req = urllib2.Request(url, None, {'User-agent': userAgent})
  fp = urllib2.urlopen(req)

Beware, some earlier versions of Python had bugs in the urllib*
libraries where it may override your setting of user agent or other
HTTP headers. This works fine for me in Python 2.3.3.



More information about the Python-list mailing list