[Python-bugs-list] httplib.HTTP.getfile() gets not the specified URL (PR#232)

Guido van Rossum guido@python.org
Sat, 11 Mar 2000 06:58:47 -0500


> Full_Name: Bastian Kleineidam
> Version: 1.5.2
> OS: Debian Linux
> Submission from: www-cache2.rz.uni-sb.de (134.96.7.103)
> 
> I request the URL http://www.calvinandhobbes.com/ and get the content of
> http://www.uexpress.com/. With other tools (wget, Netscape, Perl GET), this
> is not the case.
> Here my Python script:
> #!/usr/bin/env python
> import httplib
> h = httplib.HTTP("www.calvinandhobbes.com")
> h.putrequest("GET","/")
> h.endheaders()
> r=h.getreply()
> print r[2]
> print h.getfile().read()
> 
> What I get is the content of http://www.uexpress.com/, not the specified URL.

The website is using virtual domains.  If you add the following call
between putrequest and endheaders it will work:

h.putheader('Host', 'www.calvinandhobbes.com')

Also, consider using urllib.  You could write the whole thing in two
lines:

import urllib
print urllib.urlopen("www.calvinandhobbes.com").read()

Good luck!

--Guido van Rossum (home page: http://www.python.org/~guido/)