Python Forum
upload image with generated code from Postman does not work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
upload image with generated code from Postman does not work
#1
I'm trying to upload an image and set it to profiles of my teammates in some system. I managed to perform this request and upload the images successfully using Postman but unfortunately it doesn't work when copying the generated code/writing it by myself in the IDE...

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"PATH/TO/IMAGE.JPG\"\r\nContent-Type: text/plain\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"

headers = {
'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
'Authorization': "Basic
xxxxxxxxxxxxxxxxxxxxxxxxxxx",
'Accept': "*/*",
'Cache-Control': "no-cache",
'Host': "<host.of.site>",
'Content-Type': "multipart/form-data; boundary=--------------------------613416014226243256356192",
'Accept-Encoding': "gzip, deflate",
'Content-Length': "259378",
'Connection': "keep-alive",
'cache-control': "no-cache"
}

response = requests.request("POST", url, data=payload, headers=headers)


Here are their required fields from the documentation:


[inline]POST /api/gateway.php/sample/v1/employees/1/photo/ HTTP/1.0
Host: api.x.com
Content-Type: multipart/form-data; boundary=----MultiPart-Mime-Boundary----
Content-Length: 520

------MultiPart-Mime-Boundary----
Content-Disposition: form-data; name="file"; filename="photo.jpg"
Content-Type: text/plain

... binary file data ...

------MultiPart-Mime-Boundary------

No matter what I do, still getting "400". I would be grateful if someone here could help me! that'll be great! Thanks ahead![/inline]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  hi need help to make this code work correctly atulkul1985 5 783 Nov-20-2023, 04:38 PM
Last Post: deanhystad
  newbie question - can't make code work tronic72 2 689 Oct-22-2023, 09:08 PM
Last Post: tronic72
  HOW TO USE C# GENERATED DLL davide_vergnani 2 1,646 Jun-12-2023, 03:35 PM
Last Post: davide_vergnani
  Beginner: Code not work when longer list raiviscoding 2 821 May-19-2023, 11:19 AM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,791 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Code used to work 100%, now sometimes works! muzicman0 5 1,444 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  color code doesn't work harryvl 1 889 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  New2Python: Help with Importing/Mapping Image Src to Image Code in File CluelessITguy 0 725 Nov-17-2022, 04:46 PM
Last Post: CluelessITguy
  Something the code dont work AlexPython 13 2,244 Oct-17-2022, 08:34 PM
Last Post: AlexPython
  cannot get code to work Led_Zeppelin 10 2,450 Jun-30-2022, 06:28 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020