urllib2, debug mode

18 Jul

So one of my work projects is sending some xml via http.

We use urllib, urllib2 to do all this work. (obviously)

I needed to check what was happening to the data being sent. Since most of the work is hidden by urllib my debugging was pretty much useless.

However urllib2 allows us to switch it to debug mode like such:

import urllib, urllib2
url = "some url"
xml = "some xml"

opener = urllib2.build_opener(httphandler)
opener.addheaders = [('Accept', 'application/xml'), ('Content-Type', 'application/xml'),]

req = urllib2.Request(url)
resp = urllib2.urlopen(req)


Leave a comment

Posted by on July 18, 2011 in Uncategorized


Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: