2014-09-29 118 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()将工作。