Re: Need help to figure out urllib2.Request()
En Mon, 18 Feb 2008 09:21:10 -0200, James Yu <cyu021@xxxxxxxxx> 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
.
Relevant Pages
- Re: How could this possibly happen (HttpURLConnection + simple JSP page)
... In PHP that would throw some nasty HTTP-related warnings and potentially break the page as you are changing the headers after HTML display? ... You are writing code in a special format that is compiled in to a servlet, which is then executed by the server when the page is requested. ... The other thing is that writing things "after HTML display" is probably very difficult as the display is done on the users computer when they have recieved the response. ... When you create a response for the user it does not necessarily get sent back as soon as you start, and more importantly the headers do not necessarily finish as soon as you start writing to the body. ... (comp.lang.java.help) - Re: Whats the real content type of XHTML?
... Is that something in the HTML file itself, ... This response consists of a number of headers followed by the ... (alt.html) - Re: Igor, pAPP toolkit questions
... Thanks for your response. ... Your toolkit has just been invaluable and I ... > headers have been fully prepared. ... you suggesting I add a datastructure there to maintain the HTML info ... (microsoft.public.inetsdk.programming.webbrowser_ctl) - Re: Newsgroups with large number of posts hangs OE
... My response was an unsubtle reference to my frustration with OE's bugs. ... settings in the large NGs I susbscribe to to "headers only" then use the "Sync All" button which then proceeds to d/l all the headers of these large NGs. ... I suppose that could possibly be due to the server of that particular NG.....I dunno. ... The best way to do this is to right click on the folder name in the folder list. ... (microsoft.public.windows.inetexplorer.ie6_outlookexpress) - Re: How to set different inboxes for different accounts in OE?
... I suppose you could filter based on e-mail addresses in the To or Cc headers but those headers are *data* that the sender put into the message and which were sent during the DATA command from the e-mail client to the SMTP server. ... So your account may not be included in any e-mail addresses listed in the To or Cc headers, if any e-mail addresses are even listed. ... It still came *through* your ISP e-mail account whether or not it had the OPTIONAL To and Cc headers. ... (microsoft.public.windows.inetexplorer.ie6_outlookexpress) |
|