Hi folks,<br><br>I tried to open some web pages with urllib2.Request(url, data, headers), but it always give me a 404 error.<br>Eg.<br>url = '<a href="http://www.whatever.com/somephp.php">http://www.whatever.com/somephp.php</a>'<br>
data = {}<br>data['id'] = account<br>for i in book2Open:<br> data['book'] = i<br> url_data = urllib.urlencode(data)<br> <span style="color: rgb(0, 0, 153); font-weight: bold;">request = urllib2.Request(url, url_data, headers)</span><br>
response = urllib2.urlopen(request)<br> html = response.read()<br><span style="font-weight: bold; color: rgb(255, 0, 0);">==> HTTPError: HTTP Error 404: Not Found</span><br><br><br>However, the page is retrievable when I manually put url and data together.<br clear="all">
Eg.<br>url = '<a href="http://www.whatever.com/somephp.php">http://www.whatever.com/somephp.php</a>'<br>
data = {}<br>
data['id'] = account<br>
for i in book2Open:<br>
data['book'] = i<br>
url_data = urllib.urlencode(data)<br>
<span style="font-weight: bold; color: rgb(0, 0, 153);">full_url = url + '?' + url_data</span><br style="font-weight: bold; color: rgb(0, 0, 153);"><span style="font-weight: bold; color: rgb(0, 0, 153);">
request = urllib2.Request(full_url, "", headers)</span><br>
response = urllib2.urlopen(request)<br>
html = response.read()<br><span style="font-weight: bold; color: rgb(0, 102, 0);">==> works fine</span><br><br>Any idea ?<br><br><br>-- <br>This is a UTF-8 formatted mail<br>-----------------------------------------------<br>
James C.-C.Yu