httplib HTTPConnection request problem

deelan ggg at zzz.it
Thu Apr 1 02:07:16 EST 2004


scummer wrote:
 > 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:

dunno what's wrong with your code,  but i recently used HTTPConnection
to transfer an XML payload to an apache + webware setup. the code below
actually works:

# --- BEGIN ---

from httplib import HTTPConnection

atomMIME = 'application/x.atom+xml'
conn = HTTPConnection('locahost', 80)

print '--------------------------------'
print 'Create a new entry'
print '--------------------------------'

headers = {'Content-Type': atomMIME}
postData = '''
<?xml version="1.0" encoding="iso-8859-1"?>
<entry xmlns="http://purl.org/atom/ns#">
    <title>A post</title>
    <created>2003-08-12T23:53:03Z</created>
    <summary>An automated post</summary>
    <content type="text/html" mode="escaped">This is a test</content>
</entry>
'''.strip()

conn.request('POST','/reflex/atom/AtomHandler', postData, headers)
res = conn.getresponse()
assert res.status == 201  # created?

print res.status, res.reason

entryURI = res.msg['location']
print "location:", entryURI

print '*** PASSED ***'

conn.close()

# --- END ---



hope this helps.

-- 
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#me> a foaf:Person ; foaf:nick "deelan" ;
foaf:weblog <http://www.deelan.com/> .



More information about the Python-list mailing list