I am having some problem with a POST request that is driving me crazy. I am trying to upload an image using a POST using python requests by replicating the original request
First of all, this is the original request I can see with Firebug that the request header is:
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.7,it;q=0.3
Cache-Control no-cache
Connection keep-alive
Content-Length 26051
Content-Type multipart/form-data; boundary=--------------------------- 37693668010849786771875799013
Cookie some cookie
DNT 1
Host my.host.com
Pragma no-cache
Referer https://my.host.com/postad/1dc185ff9e814068be23ed674956a190
User-Agent Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0
X-Requested-With XMLHttpRequest
and the Body of the POST request:
-----------------------------5697279162042627623887894974
Content-Disposition: form-data; name="image"; filename="clip.jpg"
Content-Type: image/jpeg
ÿØÿà�JFIF������ÿÛ�C� .....
-----------------------------5697279162042627623887894974
Content-Disposition: form-data; name="upload"
-----------------------------5697279162042627623887894974--
This is the code I am using to upload the image:
files = {'image': ('clip.jpg', open('clip.jpg', 'rb'))}
post_image_url = "https://my.host.com/postad/563a533d9105448dbaf853f7ca0265fa/images"
r = session.post(post_image_url, files=files)
but I always get a 404 error, supposing that the request is not correct. Think I have to adjust the request to reflect the origin request examined with Firebug. I believe the request its not complete, I probably am missing the last part of the request:
-----------------------------5697279162042627623887894974
Content-Disposition: form-data; name="upload"
-----------------------------5697279162042627623887894974--
which I cannot replicate in any way.
Any idea?
thank