仅从向 Ebay 发布交易 API 调用请求中获得响应 [200]



我可以通过使用Python SDK(使用JSON代码)或通过 https://developer.ebay.com/上的API资源管理器(使用来自我与下面的Python请求库一起使用的同一XML文件中的相同XML代码)发布交易API AddItem调用,并像往常一样得到一些响应。

但是,当我尝试通过使用 xml 文件调用 Python 请求库来执行此操作时,我没有得到任何响应,而是得到了<响应>。有人可以看看下面的代码,看看我如何修复它并从 Ebay 获得正常响应吗?

法典:


import requests
# Set the name of the XML file.
xml_file = XML_FILE
headers = {'Content-Type':'text/xml', "X-EBAY-API-SITEID": "0",
"X-EBAY-API-COMPATIBILITY-LEVEL": "967",
"X-EBAY-API-CALL-NAME":"AddItem"}
# Open the XML file.
with open(xml_file) as xml:
r = requests.post('https://api.ebay.com/ws/api.dll', data=xml, headers=headers)
print(r)

我的 XML 文件:


<?xml version="1.0" encoding="utf-8"?>
<AddItemRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<RequesterCredentials>
<eBayAuthToken>TOKEN</eBayAuthToken>
</RequesterCredentials>
<ErrorLanguage>en_US</ErrorLanguage>
<WarningLevel>High</WarningLevel>
<Item>
<Title>Harry Potter and the Philosopher's Stone</Title>
<Description>
This is the first book in the Harry Potter series. In excellent condition!
</Description>
<PrimaryCategory>
<CategoryID>29223</CategoryID>
</PrimaryCategory>
<StartPrice>1.0</StartPrice>
<CategoryMappingAllowed>true</CategoryMappingAllowed>
<Country>US</Country>
<Currency>USD</Currency>
<PaymentMethods>CreditCard</PaymentMethods>
<DispatchTimeMax>3</DispatchTimeMax>
<ListingDuration>Days_7</ListingDuration>
<ListingType>Chinese</ListingType>
<PictureDetails>
<PictureURL>https://mysamplepicture.com/14.jpg</PictureURL>
</PictureDetails>
<PostalCode>95125</PostalCode>
<Quantity>1</Quantity>
<ItemSpecifics>
<NameValueList>
<Name>Title</Name>
<Value>Harry Potter and the Philosophers Stone</Value>
</NameValueList>
<NameValueList>
<Name>Publisher</Name>
<Value>Smashwords</Value>
</NameValueList>
<NameValueList>
<Name>Author</Name>
<Value>JK Rowling</Value>
</NameValueList>
<NameValueList>
<Name>Language</Name>
<Value>English</Value>
</NameValueList>
</ItemSpecifics>
<ReturnPolicy>
<ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<RefundOption>MoneyBack</RefundOption>
<ReturnsWithinOption>Days_30</ReturnsWithinOption>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
</ReturnPolicy>
<ShippingDetails>
<ShippingType>Flat</ShippingType>
<ShippingServiceOptions>
<ShippingServicePriority>1</ShippingServicePriority>
<ShippingService>USPSMedia</ShippingService>
<ShippingServiceCost>2.50</ShippingServiceCost>
</ShippingServiceOptions>
</ShippingDetails>
<Site>US</Site>
</Item>
</AddItemRequest>

你似乎对requests模块很陌生。只需阅读文档,hello world示例将解决您的问题。

我们经常将r.text用于文本,r.content用于二进制,r.json用于 json。r.status_coder.reason异常调试。

最新更新