2014-09-29 140 views
0

我正在嘗試使用ebaysdk模塊訪問Ebay API。我使用文檔中給出的示例代碼,並在易趣開發者站點上註冊以生成所需的應用程序ID。下面是我的程序的源代碼:使用Ebay API時出錯

ebaay.py

from ebaysdk.finding import Connection as Finding 

api = Finding(appid="123456789") 
response = api.execute('findItemsAdvanced', {'keywords': 'Python'}) 
print(response.dict()) 

YAML文件(假設我的應用程序ID爲123456789)

# eBay SDK Defaults 
name: ebay_api_config 
# Trading API Sandbox - https://www.x.com/developers/ebay/products/trading-api 
api.sandbox.ebay.com: 
compatability: 719 
appid: 123456789 
certid: ENTER_YOUR_CERTID_HERE 
devid: ENTER_YOUR_DEVID_HERE 
token: ENTER_YOUR_TOKEN_HERE 

# Trading API - https://www.x.com/developers/ebay/products/trading-api 
api.ebay.com: 
version: 719 
appid: 123456789 
certid: ENTER_YOUR_CERTID_HERE 
devid: ENTER_YOUR_DEVID_HERE 
token: ENTER_YOUR_TOKEN_HERE 

# Finding API - https://www.x.com/developers/ebay/products/finding-api 
svcs.ebay.com: 
appid: 123456789 
version: 1.0.0 

# Shopping API - https://www.x.com/developers/ebay/products/shopping-api 
open.api.ebay.com: 
appid: 123456789 
version: 671 
# Optional affiliate tracking 
# http://developer.ebay.com/DevZone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html#StandardURLParameters 
trackingid: ENTER_YOUR_TRACKINGID_HERE 
trackingpartnercode: ENTER_YOUR_PARTNERCODE_HERE 

然而,當我嘗試運行我的Python腳本,我遇到以下錯誤:

Traceback (most recent call last): 
    File "E:/Python27/Web Scraping/ebaay.py", line 3, in <module> 
    api = Finding(appid="123456789") 
    File "C:\Python27\lib\site-packages\ebaysdk\finding\__init__.py", line 70, in __init__ 
    config_file=kwargs.get('config_file', 'ebay.yaml')) 
    File "C:\Python27\lib\site-packages\ebaysdk\config.py", line 39, in __init__ 
    self._populate_yaml_defaults() 
    File "C:\Python27\lib\site-packages\ebaysdk\config.py", line 50, in _populate_yaml_defaults 
    for k, val in dataobj.get(self.domain, {}).items(): 
AttributeError: 'NoneType' object has no attribute 'items' 

我的代碼似乎有什麼問題?

回答

1

你需要縮進每個API領域:

# eBay SDK Defaults 
name: ebay_api_config 
# Trading API Sandbox - https://www.x.com/developers/ebay/products/trading-api 
api.sandbox.ebay.com: 
    compatability: 719 
    appid: 123456789 
    certid: ENTER_YOUR_CERTID_HERE 
    devid: ENTER_YOUR_DEVID_HERE 
    token: ENTER_YOUR_TOKEN_HERE 

# Trading API - https://www.x.com/developers/ebay/products/trading-api 
api.ebay.com: 
    version: 719 
    appid: 123456789 
    certid: ENTER_YOUR_CERTID_HERE 
    devid: ENTER_YOUR_DEVID_HERE 
    token: ENTER_YOUR_TOKEN_HERE 

# Finding API - /developers/ebay/products/finding-api 
svcs.ebay.com: 
    appid: 123456789 
    version: 1.0.0 

# Shopping API - /developers/ebay/products/shopping-api 
open.api.ebay.com: 
    appid: 123456789 
    version: 671 

而且,它不是必要投放的appid在ebaay.py您的通話Finding()如果您在ebay.yaml文件有它。 api = Finding()將工作。