Search code examples
google-app-enginehttplib

httplib.HTTPConnection in Google AppEngine


I use httplib.HTTPConnection within my app. Do I really need to provide host parameter in httplib.HTTPConnection constructor? If so, why? (I mean, I know that it's a mandatory parameter, but I wonder if I could specify None or empty string) And is there any global constant in Google AppEngine and in development server which I can use within my app in order to omit explicitly defined host.


Solution

  • If you leave it out of the constructor, how will the other methods know where to send their messages?

    The address/name of the server you're connecting to is the parameter for the HTTPConnection, the URI on that server is what goes into request.

    From the python documentation (which is the basis for AppEngine)

    h1 = httplib.HTTPConnection(host[, port[, strict[, timeout[, source_address]]]])
    h1.request(method, url[, body[, headers]])
    

    [edit]

    Remember, it may not always be you who is responsible for this code. Also, why complicate things by including so much more information in the URI when you're (for example) making calls to numerous URI's on the same website?

    [/edit]