I\'m fairly new to python, so I apologize in advance if this is something simple I\'m missing. I\'m trying to post data to a multipart form in python. The script runs, but i
import urllib, urllib2
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
def queXF():
register_openers()
url = "http://lilix2/trunk/admin/new.php"
values = {'form':open('test.pdf'),
'bandingxml':open('banding.xml'),
'desc':'description'}
data, headers = multipart_encode(values)
headers['User-Agent'] = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
request = urllib2.Request(url, data, headers)
request.unverifiable = True
response = urllib2.urlopen(request)
the_page = response.read()
Adding headers['User-Agent']
and request.unverifiable = True
seems to have fixed it.
Try using the requests library. Docs on posting multipart file are here: http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file