不理解易趣 API 的 ItemSpecifics 错误

问题描述 投票:0回答:1

我无法理解为什么我的代码会出现这个模糊的 ItemSpecifics 错误。

import ebaysdk
import csv

from ebaysdk.trading import Connection as Trading
from ebaysdk.exception import ConnectionError
from item_description import code_block
from item_definition import myitem

def addItem():

        try:
                api = Trading(config_file='ebay.yaml')

                # Open our CSV file that has individual auction item details.
                with open("auction_data.csv") as auction_data_file:
                        auction_item = csv.reader(auction_data_file)
                        # Skip headers.
                        next(auction_item, None)

                        for row in auction_item:
                                myitem["Item"]["Title"] = row[0]
                                # HTML item description template is stored in separate file. Only the item Title will be populated dynamically.
                                myitem["Item"]["Description"] = code_block.format(row[0])
                                myitem["Item"]["PrimaryCategory"]["CategoryID"] = row[1]
                                myitem["Item"]["StartPrice"] = row[2]
                                myitem["Item"]["ShippingPackageDetails"]["WeightMajor"] = row[3]
                                myitem["Item"]["ShippingPackageDetails"]["WeightMinor"] = row[4]
                                myitem["Item"]["ShippingPackageDetails"]["PackageDepth"] = row[5]
                                myitem["Item"]["ShippingPackageDetails"]["PackageWidth"] = row[6]
                                myitem["Item"]["ShippingPackageDetails"]["PackageLength"] = row[7]
                                myitem["Item"]["ScheduleTime"] = row[8]

                                # Delete all values from our PictureURL list from previous iterations.
                                myitem["Item"]["PictureDetails"]["PictureURL"] = []

                                myitem["Item"]["ItemSpecifics"]["NameValueList"].append({'Name': 'Sport', 'Value': row[9]})
                                myitem["Item"]["ItemSpecifics"]["NameValueList"].append({'Name': 'Graded', 'Value': row[10]})

                                # Last column in CSV file contains list of images delimited by pipe.
                                item_images = row[11].split('|')

                                # Upload each image to eBay and retrieve the site hosted URL, then append that to PictureURL list.
                                for image in item_images:
                                        files = {
                                                'file': ('EbayImage', open(image, 'rb'))
                                        }
                                        api.execute('UploadSiteHostedPictures', files=files)
                                        myitem["Item"]["PictureDetails"]["PictureURL"].append(api.response.dict()["SiteHostedPictureDetails"]["FullURL"])

                                # After adding auction item, print out Title and Item # for tracking.
                                api.execute('AddItem', myitem)
                                print (row[0] + ' - ' + api.response.dict()["ItemID"])

        except ConnectionError as e:
                print(e)

addItem()

错误:

Traceback (most recent call last):
  File "/Users/jay/Desktop/Random Docs/eBay Selling/eBay - Baseball Cards/list_item.py", line 59, in <module>
    addItem()
  File "/Users/jay/Desktop/Random Docs/eBay Selling/eBay - Baseball Cards/list_item.py", line 36, in addItem
    myitem["Item"]["ItemSpecifics"]["NameValueList"].append({'Name': 'Sport', 'Value': row[9]})
KeyError: 'ItemSpecifics'

我已验证我的输入文件 (auction_data.csv) 具有准确的数据:

Card Name, Category, Price, Pounds, Ounces,  Depth, Width, Length, Start Time, Sport, Graded, Images
Joe Jurevicius Auto,261328,.99,0,2,1,6,9,2023-04-11 00:00:00,Baseball,No, 1.jpg

在故障排除期间,我注释掉了 ItemSpecifics 并得到了这个错误:

'AddItem: Class: RequestError, Severity: Error, Code: 21919303, The item specific Sport\xa0is missing. The item specific Sport\xa0is missing.\xa0Add Sport to this listing, enter a valid value, and then try again., Class: RequestError, Severity: Error, Code: 21919303, The item specific Graded\xa0is missing. The item specific Graded\xa0is missing.\xa0Add Graded to this listing, enter a valid value, and then try again.'
python-3.x ebay-api
1个回答
0
投票

我不得不用这段代码更新我的项目定义文件:

"ItemSpecifics": {
        "NameValueList": []
},
© www.soinside.com 2019 - 2024. All rights reserved.