Need help to figure out urllib2.Request()
James Yu
cyu021 at gmail.com
Mon Feb 18 06:21:10 EST 2008
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/somephp.php'
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/somephp.php'
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 ?
--
This is a UTF-8 formatted mail
-----------------------------------------------
James C.-C.Yu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080218/44e71a72/attachment.html>
More information about the Python-list
mailing list