Python: using reuests library for multipart/form-data -


i noob @ , have been trying use requests modules post multipart/form-data. clarify, exact test case trying use 1 same in https://github.com/kennethreitz/requests/issues/1081. i.e. trying post without file :

--3eeaadbfda0441b8be821bbed2962e4d content-disposition: form-data; name="key1"  value1 --3eeaadbfda0441b8be821bbed2962e4d 

as per discussion on thread, tried multipart form data scheme following:

import requests requests_data_schemes import multipart_formdata mfd post_data = [('mouseaction', 'toggle'), ('zone' ,'10')] post_data = mfd(post_data) headers = {'content-type': 'multipart/form-data'}  req = requests.post(<url>, data=post_data, headers=headers) 

however, test server throwing me error saying cannot detect boundary of multipart form data.

i tried providing boundary in header too, apparently not working.

boundary = post_data[2: post_data.find('\r\n')] headers = {'content-type': 'multipart/form-data; boundary={}'.format(boundary)} 

am missing simple?

p.s. bit of surfing found few solutions using base urllib2 last resort requests lets me lot things pretty easily.

yeah bug have address. you're better off @ point doing following:

from requests.packages.urllib3.filepost import encode_multipart_formdata  (content, header) = encode_multipart_formdata([('key', 'value')]) r = requests.post(url, data=content, headers={'content-type': header}) 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

c++ - End of file on pipe magic during open -