pythonebaysdk如何动态添加物品细节?

2024-04-28 00:03:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用ebay-python-sdk 我创建了myitem对象,所以我可以api.execute('VerifyAddItem', myitem)它。 但是我需要添加一些细节,在这里我遇到了一些问题。 我有一系列由元组组成的项目细节:

a = [('Occasion', 'Casual'), ('Brand', 'Ralph Lauren'), ('Style', 'Polo Shirt')]

我想把它添加到“myitem”中。 所以我使用:

^{pr2}$

但我得到错误“keyror:”ItemSpecifics“” 我需要在代码中更改什么才能正确添加它?在

如果我把这个代码写到myitem对象,就可以了。我只是不知道如何动态地添加它。在

"ItemSpecifics": {
                "NameValueList": [
                    {"Name": "Occasion", "Value": "Casual"},
                    {"Name": "Brand", "Value": "Ralph Lauren"},
                    {"Name": "Style", "Value": "Polo Shirt"},
                    {"Name": "Sleeve Style", "Value": "Short Sleeve"}
                ]
            },

myitem对象:

myitem = {
        "Item": {
            "Title": name,
            "Description": "<![CDATA[{}]]>".format(desc),
            "PrimaryCategory": {"CategoryID": "176984"},
            "StartPrice": str(round(Decimal(start_price), 2)),
            "CategoryMappingAllowed": "true",
            "Country": "GB",
            "ConditionID": "1000",
            "Currency": "GBP",
            "DispatchTimeMax": "3",
            "ListingDuration": "{}".format(str(auction_len)),
            "ListingType": "FixedPriceItem",
            "PaymentMethods": "PayPal",
            "PayPalEmailAddress": "test@ebay.com",
            "PictureDetails": {"PictureURL": pict_list},
            "PostalCode": "bh102as",
            "ProductListingDetails":{
               "EAN": "8054241786423",
            },
            "Quantity": str(round(Decimal(qty), 0)),
            "ReturnPolicy": {
                "ReturnsAcceptedOption": "ReturnsAccepted",
                "RefundOption": "MoneyBack",
                "ReturnsWithinOption": "Days_30",
                "Description": "If you are not satisfied, return the book for refund.",
                "ShippingCostPaidByOption": "Buyer"
            },
            "ShippingDetails": [{
                "ShippingType": "Free",
                "ShippingServiceOptions": {
                    "FreeShipping": "true",
                    "ShippingServicePriority": "1",
                    "ShippingService": "ShippingMethodStandard",
                    "ShippingServiceCost": "0"
                }
            },
            {
                "ShippingType": "Flat",
                "ShippingServiceOptions": {
                    "FreeShipping": "false",
                    "ShippingServicePriority": "2",
                    "ShippingService": "UK_RoyalMailSecondClassStandard",
                    "ShippingServiceCost": "0.50"
                }
            }],
            "Site": "UK"
        }
    }

你能给我指出正确的方向吗?在

提前谢谢。在


Tags: 对象namevaluestyle细节ebayshirtbrand
1条回答
网友
1楼 · 发布于 2024-04-28 00:03:08

您得到了一个错误,因为使用x[key] = val语法只在一个层次上有效。尝试分配x[y][key] = val会导致错误,因为字典中不存在y。如果您执行myitem['Item']['ItemSpecifics']={},则在尝试在其中创建字典之前可以正常工作。或者,您可以在创建dict时立即指定它:

myitem = {
    "Item": {
        ...
        "ItemSpecifics": {}
    }
}

相关问题 更多 >