views:

20

answers:

0

I have a form that I need to post data to, however it must have a specific user agent string and HTTP/1.1 headers, (not just host it explicitly looks for HTTP/1.1 in the POST string.)

I've attempted this so far as follow:

class AppURLopener(urllib.FancyURLopener):
    version = "The User Agent String"

urllib._urlopener = AppURLopener()

def send_data(url, kv)
    params = urllib.urlencode(kv)
    f = urllib.urlopen(url, params)
    data = f.read()
    f.close()

However, this submits via HTTP/1.0 with a Host: header. Looking at the source to urllib (and urllib2) It looks like the codepaths all instantiate a HTTPLib HTTP Class object which is marked as a compatible class from 1.5... Is there an easy way to have urllib/URLOpener use HTTPConnection instead of HTTP? Or is there another solution I'm missing to have the proper headers that I need?