HTTP status code 302
I can view certain document on a Zope site over the web if I use a brower. But for fun I tried to download it by using Python's httplib, and for some Zope sites got a status code 302. This probably means I need to use another URL address. The web browser does this automatically so I don't need to do anything. But I can't seem to find the right URL. Reading from http://www.w3.org/Protocols/HTTP/HTRESP.html , it says that when 302 happens, the header line would be URI: <url> String CrLf But I don't see this line in the returned header. And the returned body is an HTML telling me the document has been moved. Funny thing is that browsers (IE, Netscape) do not have problems with it. Is this a limitation of Python's httplib (not showing the URI in the response header)? Is there a way to circumvent it? Or does this have to do with virtual hosting, or Apache stuff? Thanks, Hung Jung
Hi Hung Jung, Did you set a 'Host' header in your request? Is the request going straight to ZServer, or through Apache? (Also... do you have a SiteRoot?) These can all affect how the request is handled by the server... It woould be interesting to try urllib, rather than httplib since it handles the Host header for you... -steve
"Hung" == Hung Jung Lu <hungjunglu@hotmail.com> writes:
Hung> I can view certain document on a Zope site over the web if I Hung> use a = brower. But for fun I tried to download it by using Hung> Python's httplib, = and for some Zope sites got a status Hung> code 302. This probably means I = need to use another URL Hung> address. The web browser does this automatically = so I Hung> don't need to do anything. But I can't seem to find the Hung> right URL.=20 Hung> Reading from http://www.w3.org/Protocols/HTTP/HTRESP.html , Hung> it says that = when 302 happens, the header line would be Hung> URI: <url> String CrLf Hung> But I don't see this line in the returned header. And the Hung> returned body = is an HTML telling me the document has been Hung> moved. Funny thing is that = browsers (IE, Netscape) do not Hung> have problems with it. Hung> Is this a limitation of Python's httplib (not showing the Hung> URI in the = response header)? Is there a way to circumvent Hung> it? Or does this have to = do with virtual hosting, or Hung> Apache stuff? Hung> Thanks, Hung> Hung Jung
From: "Steve Spicklemire" <steve@spvi.com>
Did you set a 'Host' header in your request? Is the request going straight to ZServer, or through Apache? (Also... do you have a SiteRoot?) These can all affect how the request is handled by the server...
Ahh... that's it. Thank you very much!! Virtual hosting was the problem. After supplying the 'Host' header, everything was fine. The httplib offers more control, I think. It allows me to supply the 'Authorization' header. The urllib probably does not do that, right? That being said, I am still not 100% familiar with all the HTTP headers (for both request and response), it's like I learn one at a time. :) Do you know any pointer where I can get info on all the headers? regards, Hung Jung
Hi Hung, No! Urllib does that too! import urllib x = urllib.urlopen('http://user:pass@host:8080/path/to/get') print x.read() -steve
"Hung" == Hung Jung Lu <hungjunglu@hotmail.com> writes:
Hung> From: "Steve Spicklemire" <steve@spvi.com> >> Did you set a 'Host' header in your request? Is the request >> going straight to ZServer, or through Apache? (Also... do you >> have a SiteRoot?) These can all affect how the request is >> handled by the server... Hung> Ahh... that's it. Thank you very much!! Virtual hosting was Hung> the problem. After supplying the 'Host' header, everything Hung> was fine. Hung> The httplib offers more control, I think. It allows me to Hung> supply the 'Authorization' header. The urllib probably does Hung> not do that, right? Hung> That being said, I am still not 100% familiar with all the Hung> HTTP headers (for both request and response), it's like I Hung> learn one at a time. :) Do you know any pointer where I can Hung> get info on all the headers? Hung> regards, Hung> Hung Jung Hung> _______________________________________________ Zope Hung> maillist - Zope@zope.org Hung> http://lists.zope.org/mailman/listinfo/zope ** No cross Hung> posts or HTML encoding! ** (Related lists - Hung> http://lists.zope.org/mailman/listinfo/zope-announce Hung> http://lists.zope.org/mailman/listinfo/zope-dev )
participants (2)
-
Hung Jung Lu -
Steve Spicklemire