En Mon, 18 Feb 2008 09:21:10 -0200, James Yu <[EMAIL PROTECTED]> 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/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 ? The first example uses HTTP POST method; the second HTTP GET. See http://docs.python.org/lib/module-urllib2.html -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list