通过交易以编程方式更改 Ebay 图片 API
Programmatically changing Ebay pictures through Trading API
这个问题根本不是 Python 特有的,因为我知道无论使用什么 SDK,都会进行所有相同的 HTTP API 调用。
我有一堆列表(数百个)需要以编程方式更改。需要的只是改变一个项目的变体图片。使用 ReviseItem API 对我来说没有达到预期效果。
详情:
如果我对 itemID 332121070278 发出 GetItem 请求,我会收到以下响应:
<?xml version="1.0" encoding="UTF-8"?>
<GetItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2018-02-05T16:46:02.399Z</Timestamp>
<Ack>Success</Ack>
<Version>1035</Version>
<Build>E1035_INTL_API_18562923_R1</Build>
<Item>
<ItemID>332121070278</ItemID>
<Variations>
<Pictures>
<VariationSpecificName>Colour</VariationSpecificName>
<VariationSpecificPictureSet>
<VariationSpecificValue>Navy</VariationSpecificValue>
<PictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/3e11c104-311f-4faa-b308-e6d40f6a3c6a.jpg</PictureURL>
<ExternalPictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/3e11c104-311f-4faa-b308-e6d40f6a3c6a.jpg</ExternalPictureURL>
</VariationSpecificPictureSet>
<VariationSpecificPictureSet>
<VariationSpecificValue>Olive</VariationSpecificValue>
<PictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/881a11fe-bb73-4d3a-a556-cdecae2ee723.jpg</PictureURL>
<ExternalPictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/881a11fe-bb73-4d3a-a556-cdecae2ee723.jpg</ExternalPictureURL>
</VariationSpecificPictureSet>
<VariationSpecificPictureSet>
<VariationSpecificValue>Nearly Black</VariationSpecificValue>
<PictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/211f43f9-a4fd-40fd-9712-743e5ab328d0.jpg</PictureURL>
<ExternalPictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/211f43f9-a4fd-40fd-9712-743e5ab328d0.jpg</ExternalPictureURL>
</VariationSpecificPictureSet>
<VariationSpecificPictureSet>
<VariationSpecificValue>Wine</VariationSpecificValue>
<PictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/27f7768e-3987-4ff4-9440-614c0853b0cb.jpg</PictureURL>
<ExternalPictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/27f7768e-3987-4ff4-9440-614c0853b0cb.jpg</ExternalPictureURL>
</VariationSpecificPictureSet>
</Pictures>
</Variations>
</Item>
</GetItemResponse>
因此,为了在 Python SDK 中提交我的 ReviseItem 请求,我执行了以下操作:
def reviseItem(opts):
try:
api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid,
certid=opts.certid, devid=opts.devid, warnings=True, timeout=20, siteid='3')
response = api.execute('ReviseItem', {'Item': {
'ItemID': '332121070278',
'Variations': {
'Pictures': {
'VariationSpecificPictureSet': [
{
'PictureURL': 'https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519',
'ExternalPictureURL': 'https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519',
'VariationSpecificValue': 'Wine'
}
]
}
}
}})
#dump(api, full=False)
return response
except ConnectionError as e:
print(e)
print(e.response.dict())
... 当我检查实际发出的请求时,产生了预期的 XML:
<?xml version='1.0' encoding='utf-8'?>
<ReviseItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>...</eBayAuthToken>
</RequesterCredentials>
<Item>
<ItemID>332121070278</ItemID>
<Variations>
<Pictures>
<VariationSpecificPictureSet>
<ExternalPictureURL>https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519</ExternalPictureURL>
<PictureURL>https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519</PictureURL>
<VariationSpecificValue>Wine</VariationSpecificValue>
</VariationSpecificPictureSet>
</Pictures>
</Variations>
</Item>
</ReviseItemRequest>
我觉得完全正确。我可以进行其他有效的 ReviseItem API 调用(例如,我可以使用 ReviseItem 成功更改列表的标题),但是每次更改变体图像都会给我错误 "ReviseItem: Class: RequestError, Severity: Error, Code: 10007, Internal error to the application. Internal error to the application."
原来 API 不接受没有 VariationSpecificName 的 VariationSpecificPictureSet。我的 api 上面的调用完美地运行了一个小的修改:
response = api.execute('ReviseItem', {'Item': {
'ItemID': '332121070278',
'Variations': {
'Pictures': {
'VariationSpecificName': 'Colour',
'VariationSpecificPictureSet': [
{
'PictureURL': 'https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519',
'ExternalPictureURL': 'https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519',
'VariationSpecificValue': 'Wine'
}
]
}
}
}})
这个问题根本不是 Python 特有的,因为我知道无论使用什么 SDK,都会进行所有相同的 HTTP API 调用。
我有一堆列表(数百个)需要以编程方式更改。需要的只是改变一个项目的变体图片。使用 ReviseItem API 对我来说没有达到预期效果。
详情:
如果我对 itemID 332121070278 发出 GetItem 请求,我会收到以下响应:
<?xml version="1.0" encoding="UTF-8"?>
<GetItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2018-02-05T16:46:02.399Z</Timestamp>
<Ack>Success</Ack>
<Version>1035</Version>
<Build>E1035_INTL_API_18562923_R1</Build>
<Item>
<ItemID>332121070278</ItemID>
<Variations>
<Pictures>
<VariationSpecificName>Colour</VariationSpecificName>
<VariationSpecificPictureSet>
<VariationSpecificValue>Navy</VariationSpecificValue>
<PictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/3e11c104-311f-4faa-b308-e6d40f6a3c6a.jpg</PictureURL>
<ExternalPictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/3e11c104-311f-4faa-b308-e6d40f6a3c6a.jpg</ExternalPictureURL>
</VariationSpecificPictureSet>
<VariationSpecificPictureSet>
<VariationSpecificValue>Olive</VariationSpecificValue>
<PictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/881a11fe-bb73-4d3a-a556-cdecae2ee723.jpg</PictureURL>
<ExternalPictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/881a11fe-bb73-4d3a-a556-cdecae2ee723.jpg</ExternalPictureURL>
</VariationSpecificPictureSet>
<VariationSpecificPictureSet>
<VariationSpecificValue>Nearly Black</VariationSpecificValue>
<PictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/211f43f9-a4fd-40fd-9712-743e5ab328d0.jpg</PictureURL>
<ExternalPictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/211f43f9-a4fd-40fd-9712-743e5ab328d0.jpg</ExternalPictureURL>
</VariationSpecificPictureSet>
<VariationSpecificPictureSet>
<VariationSpecificValue>Wine</VariationSpecificValue>
<PictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/27f7768e-3987-4ff4-9440-614c0853b0cb.jpg</PictureURL>
<ExternalPictureURL>https://s3-eu-west-1.amazonaws.com/images.linnlive.com/b3bb06dbe22847df07835760a144c5dd/27f7768e-3987-4ff4-9440-614c0853b0cb.jpg</ExternalPictureURL>
</VariationSpecificPictureSet>
</Pictures>
</Variations>
</Item>
</GetItemResponse>
因此,为了在 Python SDK 中提交我的 ReviseItem 请求,我执行了以下操作:
def reviseItem(opts):
try:
api = Trading(debug=opts.debug, config_file=opts.yaml, appid=opts.appid,
certid=opts.certid, devid=opts.devid, warnings=True, timeout=20, siteid='3')
response = api.execute('ReviseItem', {'Item': {
'ItemID': '332121070278',
'Variations': {
'Pictures': {
'VariationSpecificPictureSet': [
{
'PictureURL': 'https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519',
'ExternalPictureURL': 'https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519',
'VariationSpecificValue': 'Wine'
}
]
}
}
}})
#dump(api, full=False)
return response
except ConnectionError as e:
print(e)
print(e.response.dict())
... 当我检查实际发出的请求时,产生了预期的 XML:
<?xml version='1.0' encoding='utf-8'?>
<ReviseItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>...</eBayAuthToken>
</RequesterCredentials>
<Item>
<ItemID>332121070278</ItemID>
<Variations>
<Pictures>
<VariationSpecificPictureSet>
<ExternalPictureURL>https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519</ExternalPictureURL>
<PictureURL>https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519</PictureURL>
<VariationSpecificValue>Wine</VariationSpecificValue>
</VariationSpecificPictureSet>
</Pictures>
</Variations>
</Item>
</ReviseItemRequest>
我觉得完全正确。我可以进行其他有效的 ReviseItem API 调用(例如,我可以使用 ReviseItem 成功更改列表的标题),但是每次更改变体图像都会给我错误 "ReviseItem: Class: RequestError, Severity: Error, Code: 10007, Internal error to the application. Internal error to the application."
原来 API 不接受没有 VariationSpecificName 的 VariationSpecificPictureSet。我的 api 上面的调用完美地运行了一个小的修改:
response = api.execute('ReviseItem', {'Item': {
'ItemID': '332121070278',
'Variations': {
'Pictures': {
'VariationSpecificName': 'Colour',
'VariationSpecificPictureSet': [
{
'PictureURL': 'https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519',
'ExternalPictureURL': 'https://cdn.shopify.com/s/files/1/0740/6535/products/wine_1_43df4936-4a20-4419-8643-40575a9bb457.jpg?v=1479773519',
'VariationSpecificValue': 'Wine'
}
]
}
}
}})