02-27-2023 12:00 AM
Hi everyone,
I use UploadSiteHostedPictures API to upload images to eBay serve.
I have a problem when Uploading Binary Images.
I also read the document carefully. But I have "XML Error Text: "{0}"." I do not know "include the picture as a binary MIME attachment after the XML input in the same POST request" as the documentation instructs.
If you have a solution, please give it to me.
Thanks.
02-27-2023 10:04 AM
This python code works:
import requests
with open("YOUR_IMG.jpg", "rb") as f:
photo = f.read()
iaf = "YOUR_TOKEN"
headers = {
"X-EBAY-API-IAF-TOKEN": iaf,
"X-EBAY-API-COMPATIBILITY-LEVEL":"1295",
"X-EBAY-API-DEV-NAME":"YOUR_DEVID",
"X-EBAY-API-APP-NAME":"YOUR_CLIENTID",
"X-EBAY-API-CERT-NAME":"YOUR_CLIENTSECRET",
"X-EBAY-API-SITEID":"0",
"X-EBAY-API-CALL-NAME": "UploadSiteHostedPictures"
}
xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><UploadSiteHostedPicturesRequest xmlns=\"urn
apis:eBLBaseComponents\"><PictureName>myphoto</PictureName><PictureSet>Supersize</PictureSet><ExtensionInDays>10</ExtensionInDays></UploadSiteHostedPicturesRequest>"
url = "https://api.sandbox.ebay.com/ws/api.dll"
data = { "XML Payload": xml.encode("UTF-8") }
files = { "myphoto": photo }
r = requests.Request(method="POST", url=url, data=data, headers=headers, files=files)
pr = r.prepare()
ses = requests.Session()
res = ses.send(pr)
print(res.content)
But it depends on the specifics of what you are using to build the request.. It is likely a header issue.
For example in the above, you leave out "Content-Type": "multipart/form-data" from the headers dict because python requests will handle that part along with setting the boundary - if I add Content-Type to the headers dict myself, it breaks it and causes python requests to not handle it correctly and i get a "XML Error Text: "{0}" response... So whatever the specifics of what you are using, it is likely doing something similar that you have to figure out what it requires.