[Tutor] confusing HTTP error while using urlopen

arsyed arsyed at gmail.com
Sat Jul 19 00:30:58 CEST 2008


It looks like the site wants an Accept header. The following works:

import urllib2
url = 'http://www.anuntul.ro/'
headers = {'Accept': 'text/html'}
req = urllib2.Request(url=url, headers=headers)
rsp = urllib2.urlopen(req)
page = rsp.read()
print page





On Fri, Jul 18, 2008 at 5:38 PM, Chad Crabtree <flaxeater at gmail.com> wrote:

> Well I can confirm this behavior.  I tried changing the user-agent
> thinking there might be some filtering based on that but no go. Still
> HTTP 400 error.  WGET works just fine though
>
> On Fri, Jul 18, 2008 at 4:31 PM, asdg asdg <mishu_yim at yahoo.com> wrote:
> > I'll skip the introduction and go right to the question cause it's as
> simple
> > as it's confusing for me.
> >
> > Why does urllib2.urlopen("http://www.anuntul.ro") return HTTPError: HTTP
> > Error 400: Bad Request, while the site opens with no problems in any
> regular
> > browser.
> >
> > Thank you in advance for answering :)
> >
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080718/d5b1d727/attachment.htm>


More information about the Tutor mailing list