A
A
alex-bul2020-06-30 02:46:05
Python
alex-bul, 2020-06-30 02:46:05

How to send photo api correctly?

For practice, I am writing a python bot that makes a comic out of photos (I use this service ). There is no official api with documentation, but I found a working version on github on typescript .

Generally. I need to send a photo to the address https://face.bubble.ru/_api/face, but when I try to send it says

b'{"errors":[{"title":"Validation error","detail":"Image should be set","status":"422","code":"6"}]}\n'

Here is the code, I would be very grateful if you can help!
file = open("test.jpg", "rb").read()
data = {"image": file}
result = requests.post("https://face.bubble.ru/_api/face",
                      data=data).content
print(result)

(code based on api call in this file )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-30
@KOT10

import requests

files = {'image': open("nums.jpeg", "rb")}
r = requests.post("https://face.bubble.ru/_api/face", files=files)

with open('result.jpg', 'wb') as f:
    f.write(r.content)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question