httplib HTTPConnection request problem
scummer
scummer at 3squares.com
Wed Mar 31 13:02:45 EST 2004
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
More information about the Python-list
mailing list