Recherches récentes
Pas de recherche récente
Smooch Upload Attachments endpoint is not working in Python
Publication le 01 avr. 2022
Hey, so I'm trying to upload an attachment using this https://docs.smooch.io/rest/#operation/uploadAttachment endpoint. It says that it takes a multipart form data as the payload where the file is sent as a "binary <string>" with the name "source". But I tried to send the file's stream as "source" in python, I get an error message saying "No source file specified".
Now when I try the same thing with postman or insomnia, it works fine. In postman/insomnia, I'm uploading a file from my local machine whereas, in python, the file is in a FileStorage format. When I do file.read(), I get the binary data. I'm not exactly sure how this is supposed to work. Here is my code sample
url = f"https://api.smooch.io/v2/apps/{self.app_id}/attachments?access=public"
headers = {
"Authorization": "Bearer {}".format(self.jwt)
}
response = requests.request(
"POST",
url,
headers=headers,
files={"source": file.read()},
)
return response.json()
Let me also show you a working example from a postman. This is what I get when I generate the code.
url = "https://api.smooch.io/v2/apps/<....>/attachments?access=public"
files=[('source',('79272208.png',open('/Users/muralikomaravolu/Downloads/79272208.png','rb'),'image/png'))]
headers = {
'Authorization': 'Bearer .....'
}
response = requests.request("POST", url, headers=headers, data={}, files=files)
0
0 commentaire
Se connecter pour laisser un commentaire.