Re: httplib HTTPConnection request problem

Discussion in 'Python' started by deelan, Apr 1, 2004.

  1. deelan

    deelan Guest

    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/> .
    deelan, Apr 1, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Httplib request method

    , Mar 22, 2005, in forum: Python
    Replies:
    0
    Views:
    962
  2. JuHui
    Replies:
    4
    Views:
    5,978
    robert
    Mar 17, 2006
  3. Replies:
    1
    Views:
    404
  4. Steven D'Aprano

    Re: Python httplib, request & putrequest

    Steven D'Aprano, Apr 9, 2013, in forum: Python
    Replies:
    0
    Views:
    121
    Steven D'Aprano
    Apr 9, 2013
  5. Brian Raymond
    Replies:
    0
    Views:
    113
    Brian Raymond
    Apr 22, 2013
Loading...

Share This Page