简体   繁体   English

Python和Json-Ebay Api上传图片错误

[英]Python & Json - Ebay Api Upload image Error

I've been trying to upload a png image to the Ebay Api with the return_file_upload call: http://developer.ebay.com/Devzone/post-order/post-order_v2_return-returnId_file_upload__post.html#Samples 我一直在尝试通过return_file_upload调用将png图片上传到Ebay Api: http : //developer.ebay.com/Devzone/post-order/post-order_v2_return-returnId_file_upload__post.html#Samples

It's weird because the documentation says it accepts an array for the data parameter but the samples doesn't use arrays. 这很奇怪,因为文档说它接受data参数的数组,但是样本不使用数组。 When I tried using an array I got a Can not deserialize instance of byte out of VALUE_STRING at [Source: java.io.SequenceInputStream@4d57f134; line: 1, column: 11] (through reference chain: com.ebay.marketplace.returns.v3.services.request.UploadFileRequest["data"]) 当我尝试使用数组Can not deserialize instance of byte out of VALUE_STRING at [Source: java.io.SequenceInputStream@4d57f134; line: 1, column: 11] (through reference chain: com.ebay.marketplace.returns.v3.services.request.UploadFileRequest["data"])获得了Can not deserialize instance of byte out of VALUE_STRING at [Source: java.io.SequenceInputStream@4d57f134; line: 1, column: 11] (through reference chain: com.ebay.marketplace.returns.v3.services.request.UploadFileRequest["data"]) Can not deserialize instance of byte out of VALUE_STRING at [Source: java.io.SequenceInputStream@4d57f134; line: 1, column: 11] (through reference chain: com.ebay.marketplace.returns.v3.services.request.UploadFileRequest["data"])

This is my code: 这是我的代码:

import json
import base64
import requests

with open("take_full_login.png", "rb") as image_file:
    encoded_string = base64.encodestring(image_file.read())
url2 = 'https://api.ebay.com/post-order/v2/return/123456/file/upload'
payload2 = {
  "data" : encoded_string,
  "filePurpose" : "LABEL_RELATED"
}
requests.post(url=url2, data=json.dumps(payload2), headers=headers)

That currently outputs {"error":[{"errorId":1616,"domain":"returnErrorDomain","severity":"ERROR","category":"REQUEST","message":"Invalid Input.","parameter":[{"value":"data","name":"parameter"}],"longMessage":"Invalid Input.","httpStatusCode":400}]} 当前输出{"error":[{"errorId":1616,"domain":"returnErrorDomain","severity":"ERROR","category":"REQUEST","message":"Invalid Input.","parameter":[{"value":"data","name":"parameter"}],"longMessage":"Invalid Input.","httpStatusCode":400}]}

Try replacing data=json.dumps(payload2) by json=payload2 尝试用json=payload2替换data=json.dumps(payload2)

The call /post-order/v2/cancellation/check_eligibility only worked that way for me 呼叫/ post-order / v2 / cancellation / check_eligibility仅对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM