使用Ebay API时出错

时间:2014-09-29 13:42:31

标签: python ebay-api

我尝试使用ebaysdk模块访问Ebay API。我使用文档中给出的示例代码并在Ebay Developer的网站上注册以生成所需的App ID。这是我的程序的源代码:

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 个答案:

答案 0 :(得分: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

此外,如果您在ebay.yaml文件中有appid,则无需将appid放入ebaay.py中的Finding()电话中。 api = Finding()可以使用。