Doesn't work (was: Re: httplib won't accept URL with parameters (???))

pythonhda pythonhda at yahoo.com.replacepythonwithlinux
Tue Jan 7 19:13:23 EST 2003


I'm using python 2.2.1

This works for me...I get the source of the page:

import httplib

USER_AGENT = "Navigator"


class ServerGet:

    def __init__(self, host):
        self.host = host
        
    def fetch(self, path):
        http = httplib.HTTP(self.host)

        # write header
        http.putrequest("GET", path)
        http.putheader("User-Agent", USER_AGENT)
        http.putheader("Host", self.host)
        http.putheader("Accept", "*/*")
        http.endheaders()
        
        # get response
        errcode, errmsg, headers = http.getreply()

        
        file = http.getfile()
        data = file.read()
        http.close()
        return data

CompareServer = ServerGet("www.server.com")
ComparePage = CompareServer.fetch("/grab/database/get-page/link=ddb_benutzt_a/00b-97rt692-8ab6561?view=fixed-thing&field-stuff-type=used&thing-number=3897211920&field-status=open&size=25&rank=+parameter")

print ComparePage

---
Maybe our versions conflict? Check section 11.6.2 in the library reference. It is a little different from your version. I believe you're using an antiquated class "HTTP". The doc string for *me* says: 'Compatibility class with httplib.py from 1.5.'. So not being microsoft, I won't say "Upgrade!" :) - We're probably not speaking the same version...



On Tue, 7 Jan 2003 23:29:30 +0100
Phillip <ritschratsch at gmx.de> wrote:

> pythonhda wrote:
> 
> > See the code changes below...
> 
> >> file = http.getfile()
> >  data = file.read() ####
> > http.close()       ####
> > return data        ####
> >> 
> >> CompareServer = ServerGet("www.server.com")
> >> ComparePage =
> >> 
> CompareServer.fetch("""/grab/database/get-page/link=ddb_benutzt_a/00b-97rt
>         692-8ab6561?view=fixed-thing&field-stuff-type=used&thing-number=
>         3897211920&field-status=open&size=25&rank=+parameter""")
> >> # long URL, I know....
> >> print ComparePage
> 
> Thanks for the help, but:
> This still won't work. Here's the same error I get:
> >>>>>>
> Traceback (most recent call last):
>   File "browse.py", line 166, in ?
>     MyFetch.compare()
>   File "browse.py", line 144, in compare
>     DataFetchWrite.write(CompareServer1.fetch(CompareURL))
>   File "browse.py", line 47, in fetch
>     data = file.read()
> AttributeError: 'None' object has no attribute 'read'
> <<<<<<
> 
> As I said, httplib(!!!) won't return *anything*! Your little addition 
> doesn't repair that. ServerGet seems OK, I don't see your point in copying 
> the stuff - except form maybe closing the connection.
> I just can't figure....any other idea?
> 
> --
> Phillip




More information about the Python-list mailing list