EXAMPLE:
Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
>>> con=urllib2.urlopen('http://www.google.it/search')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/urllib2.py", line 138, in urlopen
return _opener.open(url, data)
File "/usr/lib/python2.2/urllib2.py", line 322, in open
'_open', req)
File "/usr/lib/python2.2/urllib2.py", line 301, in _call_chain
result = func(*args)
File "/usr/lib/python2.2/urllib2.py", line 785, in http_open
return self.do_open(httplib.HTTP, req)
File "/usr/lib/python2.2/urllib2.py", line 779, in do_open
return self.parent.error('http', req, fp, code, msg, hdrs)
File "/usr/lib/python2.2/urllib2.py", line 348, in error
return self._call_chain(*args)
File "/usr/lib/python2.2/urllib2.py", line 301, in _call_chain
result = func(*args)
File "/usr/lib/python2.2/urllib2.py", line 400, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 403: Forbidden
>>>
What can I do to repair the situation?
Help me please!!!
Thanks...
-Ennio-
That's not a bug in urllib2; google.it is *really* returning 403
FORBIDDEN.
It appears that this google behaviour is triggered by the header
User-agent: Python-urllib/2.0a1
that urllib2 sends, which, in turn, suggests that Google explicitly bans
urllib2.
Complain to them.
Regards,
Martin
Thanks to all them that helped me swiftly!!!
How can I change User-Agent field presents inside "urllib2"?
I find two variables that (I think) define user agent in "urllib2"
library: "__name__" and "__version__".
I tested to set them following way:
__name__="Mozzilla"
__version__="5.0"
but it failed yet!!!
Whatever suggest is accept!!!
- Ennio Viola -
Thanks to all them that helped me swiftly!!!
Thanks to all them that helped me swiftly!!!