[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Need help to figure out urllib2.Request

Gabriel Genellina

2/18/2008 8:26:00 PM

En Mon, 18 Feb 2008 09:21:10 -0200, James Yu <cyu021@gmail.com> escribi�:

> Hi folks,
>
> I tried to open some web pages with urllib2.Request(url, data, headers),
> but
> it always give me a 404 error.
> Eg.
> url = 'http://www.whatever.com/someph...
> data = {}
> data['id'] = account
> for i in book2Open:
> data['book'] = i
> url_data = urllib.urlencode(data)
> request = urllib2.Request(url, url_data, headers)
> response = urllib2.urlopen(request)
> html = response.read()
> ==> HTTPError: HTTP Error 404: Not Found
>
>
> However, the page is retrievable when I manually put url and data
> together.
> Eg.
> url = 'http://www.whatever.com/someph...
> data = {}
> data['id'] = account
> for i in book2Open:
> data['book'] = i
> url_data = urllib.urlencode(data)
> full_url = url + '?' + url_data
> request = urllib2.Request(full_url, "", headers)
> response = urllib2.urlopen(request)
> html = response.read()
> ==> works fine
>
> Any idea ?

The first example uses HTTP POST method; the second HTTP GET.
See http://docs.python.org/lib/module-ur...

--
Gabriel Genellina