1

有人使用 python 使用 API 向 Etsy 添加列表吗?我正在使用requests_oauthlib,但是想将图像上传到列表时不断出错。其他功能,如列表创建等。图片上传代码:

self.oauth = OAuth1(self.api_key,
                    client_secret=self.api_secret,
                    resource_owner_key=self.oauth_token,
                    resource_owner_secret=self.oauth_token_secret)

def upload_picture(self):
    url = "https://openapi.etsy.com/v2/listings/{listing_id}/images"
    headers = {
        "Content-Type": "multipart/form-data",
    }
    request = {
        'image': ('img8.jpg', open('./img8.jpg', 'rb'), 'image/jpeg'),
    }

    r = requests.post(url=url, params=request, auth=self.oauth, headers=headers)

    print(r.content)

错误:

oauth_problem=signature_invalid

提前致谢!

4

1 回答 1

1

我不能那样做。我不确定为什么。
但以下对我有用:

etsy = OAuth1Session(
    ApplicationKey,
    ApplicationSecret,
    token, token_secret
)

url = "https://openapi.etsy.com/v2/listings/{listing_id}/images"
request = { 'image': open('./img8.jpg', 'rb') }

response = etsy.post(url, files = request)

我是 OAuth 和 Etsy API 的新手

于 2020-08-31T09:10:44.047 回答