0

Trying to post an image from file to this website [https://demo.neural-university.ru/emotion-recognition.html?ysclid=lauqlu1uq6710345308] It asks to post an image like this: curl -X POST -F "od_content=@1.jpg" https://srv2.demo.neural-university.ru/emotion_recognition/

I tried it with the file "user_photo_510495289.jpg" , using requests.post

import requests
url = 'https://srv2.demo.neural-university.ru/emotion_recognition/'

files = {'od_content': open('user_photo_510495289.jpg', 'rb')}
data = {'od_content': open('user_photo_510495289.jpg', 'rb').read()}
requests.post(url, data=data)
#requests.post(url, files=files)

Neither posting with "data", nor with "files" didn't work. Is it a problem with a posting request or with website API?

Tried posting what was mentioned previously, json-file is expected

SkyPan
  • 1
  • 1

1 Answers1

0

Are you sure this endpoint is not needed for authorization? I think it needs authorization, you can use it this code;

import requests

url = "your URL"

payload={}
files=[
  ('upload_file',('20220212235319_1509.jpg',open('/20220212235319_1509.jpg','rb'),'image/jpeg'))
]
headers = {
  'Accept-Language': 'en-US',
  'Authorization': 'Bearer yourToken'
}

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

print(response.text)

or basic auth;

import requests

url = "https://example.com"
payload={}
files=[
  ('file',('myfile.jpg',open('/path/to/myfile.jpg','rb'),'image/jpeg'))
]

response = requests.request("POST", url, auth=("my_username","my_password"), data=payload, files=files)
print(response.text)

for more details; Upload Image using POST form data in Python-requests

Sezer BOZKIR
  • 534
  • 2
  • 13