Answer the question
In order to leave comments, you need to log in
Get file from post request (WildBerries)?
Hello, I decided to automate some processes using the WildBerry API.
The request works, everything is fine. But, the request must return a pdf file, example:
Code:
import requests
def get_pdf():
data = {
"orderIds": [199420617],
"type": "code128",
"width": 58,
}
headers = {" Authorization": "token"}
request = requests.post(' https://suppliers-api.wildberries.ru/api/v2/orders... ', headers=headers, json=data)
r_json = request.json( )
print(r_json)
# pdf_data = str.encode(r_json['data']['file'
{'error': False, 'errorText': '', 'additionalErrors': None, 'data': {'file': 'JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL01lZGlhQm94IFswIDAgMTEzLjM5IDg1LjA0XQovUmVzb3VyY2VzIDIgMCBSCi9Db250ZW50cyA0IDAgUj4 + CmVuZG9iago0IDAgb2JqCjw8L0ZpbHRlciAvRmxhdGVEZWNvZGUgL0xlbmd0aCAyMjE + PgpzdHJlYW0KeAGUzT1OQzEQReHeq7glKZhcjz22p40ICLpI3oDfX6RICIWG7SP0aCmojk71EW + BuAWKVXwFCkm8 / PYa7ohUYa6aQRAWhZqKwqQUV4c2Sbnkgvkdx9dJfZjXuHhay9TyyNzmdUy + bSNzMprqSHPC0wcuYceuwaRUqEppu2Z43O9zxRZOHcdnjloqbYltZfa8LJrnyWpaLY3B0eYauc7uiCok + oZzD3dEIYkrTh1NjGhiRF / wYBo1pwP6DeeOS / gfovoHYllcodISfhRG9wP6DeeOS / gOAAD // 6VmUpAKZW5kc3RyZWFtCmVuZG9iagoxIDAgb2JqCjw8L1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUiBdCi9Db3VudCAxCi9NZWRpYUJveCBbMCAwIDU5NS4yOCA4NDEuODldCj4 + CmVuZG9iago1IDAgb2JqCjw8L1R5cGUgL0ZvbnQKL0Jhc2VGb250IC9IZWx2ZXRpY2EKL1N1YnR5cGUgL1R5cGUxCi9FbmNvZGluZyAvV2luQW5zaUVuY29kaW5nCj4 + CmVuZG9iago2IDAgb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Dw8Ci9FbWJlZGRlZEZpbGVzIDw8IC9OYW1lcyBbCiAgCl0gPj4KPj4KPj4KZW5kb2JqCnhyZWYKMCA5CjAwMDAwMDAwMDAgNjU1MzUgZiAKMDAwMDAwMDQwNyAwMDAwMCBuIAowMDAwMDAxODA3IDAwMDAwIG4gCjAwMDAwMDAwMDkgMDAwMDAgbiAKMDAwMDAwMDExNiAwMDAwMCBuIAowMDAwMDAwNDk0IDAwMDAwIG4gCjAwMDAwMDA1OTAgMDAwMDAgbiAKMDAwMDAwMjAxNyAwMDAwMCBuIAowMDAwMDAyMTMwIDAwMDAwIG4gCnRyYWlsZXIKPDwKL1NpemUgOQovUm9vdCA4IDAgUgovSW5mbyA3IDAgUgo + PgpzdGFydHhyZWYKMjIyNwolJUVPRgo = ',' name ':' stickers.pdf ',' mimeType ':' application / pdf '}}}}}}}}}}}}}}}}}}}}}}}}}}
The option to save in this form does not work:
with open(f"D:\\Projects\\FBS-sticker\\data\\21.pdf", 'wb') as s:
s.write(pdf_data)
I will be very happy for any help. Thanks in advance, all the best!
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question