I am trying to send a POST message with a purely XML payload (I think) using urllib2 in IronPython. However, every time I send it, it returns error code 400 (failed request).
I'm actually trying to mimic Boxee to remove a queue point call for which the actual data packets look like this (from WireShark):
POST /action/add HTTP/1.1 User-Agent: curl/7.16.3 (Windows build 7600; en-US; beta) boxee/0.9.21.11487 Host: app.boxee.tv Accept: */* Accept-Encoding: deflate, gzip Cookie: boxee_ping_version=9; X-Mapping-oompknoc=76D730BC9E858725098BF13AEFE32EB5; boxee_app=e01e36e85d368d4112fe4d1b6587b1fd Connection: keep-alive Content-Type: text/xml Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Accept-Language: en-us,en;q=0.5 Keep-Alive: 300 Connection: keep-alive Content-Length: 53 <message type="dequeue" referral="3102296"></message>
I am using the following python code to send a POST:
def PostProtectedPage(theurl, username, password, postdata): req = urllib2.Request(theurl, data=postdata) req.add_header('Content-Type', 'text/xml') try: handle = urllib2.urlopen(req) except IOError, e:
However, whenever I run this, it returns Error 400 (Bad Request)
I know that authentication is correct because I use it elsewhere to retrieve the queue (and I canβt imagine that it is not being used, otherwise now, in which account will the change be applied?)
Looking at network capture, can I just skip adding some headers to the request? Probably something simple, but I just don't know enough about python or HTTP requests to find out what.
Edit : BTW, I call the code as follows (it is really dynamic, but this is the main idea):
PostProtectedPage("http://app.boxee.tv/action/add", "user", "pass", "<message type=\"dequeue\" referral=\"3102296\"></message>")