【发布时间】:2020-07-09 10:40:39
【问题描述】:
我正在创建一个脚本来使用 python 将列表图像上传到 etsy。
但是,当我执行它时,它会返回一条消息 "图像数组元数据看起来不像 _FILES 数组"
顺便说一句,我正在使用库https://github.com/mcfunley/etsy-python
我试过这段代码:
product_image = open(filename)
result = etsy.uploadListingImage(listing_id=listing_id, image=product_image)
但它会返回错误消息“UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte”
我又试了一个:
product_image = {filename, open(filename, 'rb'), 'image/jpeg'}
result = etsy.uploadListingImage(listing_id=listing_id, image=product_image)
但它会返回错误消息“图像数组元数据看起来不像 _FILES 数组”
有一个用于 php (https://www.etsy.com/developers/documentation/getting_started/images#section_uploading_images) 的示例代码,但我很难将它与我使用的 python 库保持一致。
$source_file = dirname(realpath(__FILE__)) ."/$filename";
$url = "https://openapi.etsy.com/v2/listings/".$listing_id."/images";
$params = array('@image' => '@'.$source_file.';type='.$mimetype);
$oauth->fetch($url, $params, OAUTH_HTTP_METHOD_POST);
$json = $oauth->getLastResponse();
所以我认为主要问题是uploadListingImage的图像参数的变量类型或结构。
【问题讨论】:
标签: python python-3.x image file etsy