简体   繁体   中英

Etsy API python image upload

does anyone use python for adding listings to Etsy using API? I am using requests_oauthlib, but keep getting error when want to upload image to listing. Other functions, like listing creation etc. are working. Code of image upload:

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)

error:

oauth_problem=signature_invalid

Thanks in advance!

I wasn't able to do it like that. I'm not sure why.
But below worked for me:

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)

I'm new to both OAuth & Etsy API

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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