python - POST request with Multipart/form-data. Content-type not correct -


we're trying write script python (using python-requests a.t.m.) post request site content has multipartformdata. when post request manually (by filling in form on site , post), using wireshark, came (short version):

content-type: multipart/form-data; content-disposition: form-data; name="name" data (8 bytes)     john doe 

when try use python-requests library achieving same result, sent:

content-type: application/x-pandoplugin content-disposition: form-data; name="name"; filename="name"\r\n media type: application/x-pandoplugin (12 bytes)     //and in piece posted://     john doe 

the weird thing 'general type' of packet indeed multipart/form-data, individual item sent (key = 'name', value= 'john doe') has type application/x-pandoplugin (a random application on pc guess).

this code used:

response = s.post('http://url.com', files={'name': 'john doe'}) 

is there way specify content-type of individual items instead of using headers argument (which changes type of 'whole' packet)?

we think server doesn't respond correctly due fact can't understand content-type send it.

little update: think different parts of multipart content identical ones sent if post in browser, that's good. still server doesn't changes send script. thing still different order of different parts.

for example browser sends:

boundary: \r\n------webkitformboundary3exdyo1lg8pgxjwj\r\n encapsulated multipart part:  (text/plain)     content-disposition: form-data; name="file"; filename="ex.txt"\r\n     content-type: text/plain\r\n\r\n     line-based text data: text/plain         lore ipsum blabbla  boundary: \r\n------webkitformboundary3exdyo1lg8pgxjwj\r\n encapsulated multipart part:      content-disposition: form-data; name="seq"\r\n\r\n     data (2 bytes)  boundary: \r\n------webkitformboundary3exdyo1lg8pgxjwj\r\n encapsulated multipart part:      content-disposition: form-data; name="name"\r\n\r\n     data (2 bytes) 

and script (using python-requests) sends:

boundary: \r\n------webkitformboundary3exdyo1lg8pgxjwj\r\n encapsulated multipart part:      content-disposition: form-data; name="name"\r\n\r\n     data (2 bytes)  boundary: \r\n------webkitformboundary3exdyo1lg8pgxjwj\r\n encapsulated multipart part:  (text/plain)     content-disposition: form-data; name="file"; filename="ex.txt"\r\n     content-type: text/plain\r\n\r\n     line-based text data: text/plain         lore ipsum blabbla  boundary: \r\n------webkitformboundary3exdyo1lg8pgxjwj\r\n encapsulated multipart part:      content-disposition: form-data; name="seq"\r\n\r\n     data (2 bytes) 

could possible server counts on order of parts? according multipart upload form: order guaranteed?, apparently is? , if so, possible explicitly force order using requests library? , make things worse in case: there mixture of file , text values.

so forcing order seems rather difficult. current way it:

s.post('http://www.url.com', files=files,data = form_values) 

edit2: did modification in requests plugin make sure order of parts same in original request. doesn't fix problem guess there no straightforward solution problem. i'll send mail devs of site , hope can me!

your code looks correct.

requests.post('http://url.com', files={'name': 'john doe'}) 

... , should send 'multipart/form-data' post.

and indeed, posted:

accept-encoding: gzip, deflate, compress connection: close accept: */* content-length: 188 content-type: multipart/form-data; boundary=032a1ab685934650abbe059cb45d6ff3 user-agent: python-requests/1.2.3 cpython/2.7.4 linux/3.8.0-27-generic  --032a1ab685934650abbe059cb45d6ff3 content-disposition: form-data; name="name"; filename="name" content-type: application/octet-stream  john doe --032a1ab685934650abbe059cb45d6ff3-- 

i have no idea why you'd weird content-type header:

content-type: application/x-pandoplugin 

i begin removing pando web plugin machine completely, , try python-requests code again. (or try different machine)


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -