我可以通過使用 Python SDK(使用 JSON 代碼)或通過https://developer.ebay.com/上的 API 資源管理器發布 Trading API AddItem 呼叫(使用與 Python requests 庫一起使用的同一 XML 檔案中的相同 XML 代碼下面)并像往常一樣得到一些回應。
但是,當我嘗試通過使用 xml 檔案呼叫 Python 請求庫來執行此操作時,我沒有得到任何回應,而是得到了 <Response [200]>。有人可以看看我下面的代碼,看看我如何修復它并從 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>
uj5u.com熱心網友回復:
您似乎對requests模塊很陌生。只需閱讀檔案,hello world 示例將解決您的問題。
我們經常使用r.text文本,r.content二進制,r.jsonjson。r.status_code并r.reason用于例外除錯。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/444714.html
