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 == 'getFreeBusyInf o' all functions perfectly, but when
req == 'conflictReques t' 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.HTTPCon nection('my.pro xy.org', 3128)
self.h1 = httplib.HTTPCon nection('xxx.xx x.xxx.xxx', 80)
def sendInfo(self, req, confDict, xml=None):
print xml
if req == 'getFreeBusyInf o':
self.h1.putrequ est('GET',
self.server+"/servlet/webdav.freebusy ?username="+con fDict['users']+"&server=netli ne.de&start="+s tr(confDict['request_start'])+"&end="+str(c onfDict['request_end']))
self.h1.puthead er('Accept-Language', 'de, en-us;q=0.2')
self.h1.puthead er('Translate', 'f')
self.h1.puthead er('User-Agent', 'SLOX HolidayInfo')
self.h1.puthead er('Host', self.server)
self.h1.endhead ers()
elif req == 'conflictReques t':
self.h1.putrequ est("POST",
self.server+"/servlet/webdav.calendar/conflict.xml")
self.h1.puthead er("Accept-Language", "de, en-us;q=0.2")
self.h1.puthead er("Translate" , "f")
self.h1.puthead er("User-Agent", "SLOX HolidayInfo")
self.h1.puthead er("Host", confDict['server'])
self.h1.puthead er("Content-Length", str(len(xml)))
self.h1.puthead er("Authorizati on", "Basic
"+str(confD ict['base64Auth']))
self.h1.endhead ers()
self.h1.send(xm l)
#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(confD ict['base64Auth'])}
#self.h1.reques t('POST',
self.server+"/servlet/webdav.calendar/conflict.xml", headers, xml)
def receiveInfo(sel f):
rec = self.h1.getresp onse()
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:multista tus
xmlns:D="DAV:"> <D:propertyupda te
xmlns:D="DAV">< D:set><D:prop>< S:begins
xmlns:S="SLOX:" >108180720000 0</S:begins><S:end s
xmlns:S="SLOX:" >108197994000 0</S:ends><S:clien tid
xmlns:S="SLOX:" >HolidyInfoID </S:clientid><S:f olderid
xmlns:S="SLOX:" ></S:folderid><S:t itle xmlns:S="SLOX:" >HolidayInfo
Conflict Request</S:title><S:appo intment_request
xmlns:S="SLOX:" >yes</S:appointment_r equest><S:membe rs
xmlns:S="SLOX:" ><S:member>xyzx yz</S:member></S:members></D:prop></D:set></D:propertyupdat e></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
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 == 'getFreeBusyInf o' all functions perfectly, but when
req == 'conflictReques t' 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.HTTPCon nection('my.pro xy.org', 3128)
self.h1 = httplib.HTTPCon nection('xxx.xx x.xxx.xxx', 80)
def sendInfo(self, req, confDict, xml=None):
print xml
if req == 'getFreeBusyInf o':
self.h1.putrequ est('GET',
self.server+"/servlet/webdav.freebusy ?username="+con fDict['users']+"&server=netli ne.de&start="+s tr(confDict['request_start'])+"&end="+str(c onfDict['request_end']))
self.h1.puthead er('Accept-Language', 'de, en-us;q=0.2')
self.h1.puthead er('Translate', 'f')
self.h1.puthead er('User-Agent', 'SLOX HolidayInfo')
self.h1.puthead er('Host', self.server)
self.h1.endhead ers()
elif req == 'conflictReques t':
self.h1.putrequ est("POST",
self.server+"/servlet/webdav.calendar/conflict.xml")
self.h1.puthead er("Accept-Language", "de, en-us;q=0.2")
self.h1.puthead er("Translate" , "f")
self.h1.puthead er("User-Agent", "SLOX HolidayInfo")
self.h1.puthead er("Host", confDict['server'])
self.h1.puthead er("Content-Length", str(len(xml)))
self.h1.puthead er("Authorizati on", "Basic
"+str(confD ict['base64Auth']))
self.h1.endhead ers()
self.h1.send(xm l)
#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(confD ict['base64Auth'])}
#self.h1.reques t('POST',
self.server+"/servlet/webdav.calendar/conflict.xml", headers, xml)
def receiveInfo(sel f):
rec = self.h1.getresp onse()
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:multista tus
xmlns:D="DAV:"> <D:propertyupda te
xmlns:D="DAV">< D:set><D:prop>< S:begins
xmlns:S="SLOX:" >108180720000 0</S:begins><S:end s
xmlns:S="SLOX:" >108197994000 0</S:ends><S:clien tid
xmlns:S="SLOX:" >HolidyInfoID </S:clientid><S:f olderid
xmlns:S="SLOX:" ></S:folderid><S:t itle xmlns:S="SLOX:" >HolidayInfo
Conflict Request</S:title><S:appo intment_request
xmlns:S="SLOX:" >yes</S:appointment_r equest><S:membe rs
xmlns:S="SLOX:" ><S:member>xyzx yz</S:member></S:members></D:prop></D:set></D:propertyupdat e></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
Comment