httplib HTTPConnection request problem

From: scummer (scummer_at_3squares.com)
Date: 03/31/04


Date: 31 Mar 2004 10:02:45 -0800

Hi,

I am having a problem with the httplib HTTPConnection object. While I
can easily send requests that don't have any payload (ie. "get"), I
encounter issues if I want to post xml data. If you look at the class
below, when req == 'getFreeBusyInfo' all functions perfectly, but when
req == 'conflictRequest' I run into problems of the nature "400 Bad
Request". As you will notice, I also tried the shorter HTTPConnection
instance method "request", feeding it a dictionary of the header
arguments and the xml payload, but that didn't fly either. With the
headers in this format, I get the error:

AttributeError: 'str' object has no attribute 'iteritems' in line 737
of httplib.py

However, this dictionary format is exactly the same as what I found in
an example in the python documentation.

Class description and example of the xml payload are as follows:

class Connector:
        def __init__(self, server):
                self.server = 'http://'+server
                #self.h1 = httplib.HTTPConnection('my.proxy.org', 3128)
                self.h1 = httplib.HTTPConnection('xxx.xxx.xxx.xxx', 80)

        def sendInfo(self, req, confDict, xml=None):
                print xml
                if req == 'getFreeBusyInfo':
                        self.h1.putrequest('GET',
self.server+"/servlet/webdav.freebusy?username="+confDict['users']+"&server=netline.de&start="+str(confDict['request_start'])+"&end="+str(confDict['request_end']))
                        self.h1.putheader('Accept-Language', 'de, en-us;q=0.2')
                        self.h1.putheader('Translate', 'f')
                        self.h1.putheader('User-Agent', 'SLOX HolidayInfo')
                        self.h1.putheader('Host', self.server)
                        self.h1.endheaders()
                elif req == 'conflictRequest':
                        self.h1.putrequest("POST",
self.server+"/servlet/webdav.calendar/conflict.xml")
                        self.h1.putheader("Accept-Language", "de, en-us;q=0.2")
                        self.h1.putheader("Translate", "f")
                        self.h1.putheader("User-Agent", "SLOX HolidayInfo")
                        self.h1.putheader("Host", confDict['server'])
                        self.h1.putheader("Content-Length", str(len(xml)))
                        self.h1.putheader("Authorization", "Basic
"+str(confDict['base64Auth']))
                        self.h1.endheaders()
                        self.h1.send(xml)
                        #headers = {"Accept-Language": "de, en-us;q=0.2", "Translate": "f",
"User-Agent": "SLOX HolidayInfo", "Host": confDict['server'],
"Content-Length": str(len(xml)), "Authorization": "Basic
"+str(confDict['base64Auth'])}
                        #self.h1.request('POST',
self.server+"/servlet/webdav.calendar/conflict.xml", headers, xml)

        def receiveInfo(self):
                rec = self.h1.getresponse()
                return rec

        def closeConnection(self):
                print 'Closing connection....'
                self.h1.close()
                

The XML data looks something like this:
                                
<?xml version="1.0" encoding="UTF-8"?><D:multistatus
xmlns:D="DAV:"><D:propertyupdate
xmlns:D="DAV"><D:set><D:prop><S:begins
xmlns:S="SLOX:">1081807200000</S:begins><S:ends
xmlns:S="SLOX:">1081979940000</S:ends><S:clientid
xmlns:S="SLOX:">HolidyInfoID</S:clientid><S:folderid
xmlns:S="SLOX:"></S:folderid><S:title xmlns:S="SLOX:">HolidayInfo
Conflict Request</S:title><S:appointment_request
xmlns:S="SLOX:">yes</S:appointment_request><S:members
xmlns:S="SLOX:"><S:member>xyzxyz</S:member></S:members></D:prop></D:set></D:propertyupdate></D:multistatus>

Incidentally, I set this same thing up using sockets and everything
worked perfectly. However, I need to now use with a proxy so that is
why I moved to the httplib module. I also tried the urllib2 module
but the only request data to be sent is
application/x-www-form-urlencoded and I need to send xml.

If someone can help me out here, I would certainly appreciate it.

Thanks,

Scum



Relevant Pages

  • Re: Design involving composition of inherited members.
    ... I am designing classes to work with an API. ... The API operates via XML ... Each API call involves sending a request and ... If the data packets' semantics are unique to each messageID, then each API method would know which particular serialization to use. ...
    (comp.object)
  • Re: IIS returns status code 200 even if XML is invalid
    ... ASMX requests are handled by ASP.NET ... when there is a problem with an XML being sent to the server ... The request is not being handled by the "designated method" which ... That HTTP 1.1 200 OK return code means the the HTTP request/connection ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: FAQ/FAQ notes site makeover
    ... VK suggested and XML procedure. ... Randy Webb wrote: ... easy to add a script-driven request generator with each topic having ... possibly that FAQ topics will not accomodate all and every accumulated ...
    (comp.lang.javascript)
  • Re: Windows CE, WideCharToMultiByte, HttpSendRequestEx prob with Unic
    ... > There is an payload we are sending in InternetWriteFile ... > Following is the code we are using to do the whole process of send request ... > HINTERNET hRequest = NULL; ... > // Call HttpQueryInfo to find out the size of the headers. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: WideCharToMultiByte, HttpSendRequestEx problem with Unicode
    ... > There is an payload we are sending in InternetWriteFile ... > Following is the code we are using to do the whole process of send request ... > HINTERNET hRequest = NULL; ... > // Call HttpQueryInfo to find out the size of the headers. ...
    (microsoft.public.pocketpc.developer)