urllib2 - 403 that _should_ not occur.
Falcolas
garrickp at gmail.com
Tue Jan 13 11:49:51 EST 2009
On Jan 11, 6:59 pm, "James Mills" <prolo... at shortcircuit.net.au>
wrote:
> Hey all,
>
> The following fails for me:
>
> >>> from urllib2 import urlopen
> >>> f = urlopen("http://groups.google.com/group/chromium-announce/feed/rss_v2_0_msgs.xml")
For what it's worth, I've had a similar problem with the urlopen as
well. Using the library default urlopen results in an error, but if I
build an opener with the basic handlers, it works just fine.
>>> import urllib2
>>> f = urllib2.urlopen("http://localhost:8000")
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
f = urllib2.urlopen("http://localhost:8000")
File "C:\Python25\lib\urllib2.py", line 121, in urlopen
return _opener.open(url, data)
File "C:\Python25\lib\urllib2.py", line 380, in open
response = meth(req, response)
File "C:\Python25\lib\urllib2.py", line 491, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python25\lib\urllib2.py", line 418, in error
return self._call_chain(*args)
File "C:\Python25\lib\urllib2.py", line 353, in _call_chain
result = func(*args)
File "C:\Python25\lib\urllib2.py", line 499, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden
>>> opener = urllib2.OpenerDirector()
>>> opener.add_handler(urllib2.HTTPHandler())
>>> opener.add_handler(urllib2.HTTPDefaultErrorHandler())
>>> f = opener.open("http://localhost:8000")
>>> f.read()
'something relevant'
More information about the Python-list
mailing list