[英]authentication error in eBay Python Finding API
我正在尝试使用ebay.yaml
文件将我的应用程序密钥(特别是我的应用程序 ID)快速传递到 Finding API。 但是,即使文件与程序在同一目录中,每次运行程序时它也会抛出此异常:
2020-01-22 23:45:34,335 ebaysdk [DEBUG]:execute: verb=findItemsByKeywords data={'keywords': 'buffalo
nickel coin', 'itemFilter': [{'name': 'condition', 'value': 'new'}], 'paginationInput':
{'entriesPerPage': 10, 'pageNumber': 1}, 'sortOrder': 'PricePlusShippingLowest'}
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/utils.py", line 868, in check_header_validity
if not pat.match(value):
TypeError: expected string or bytes-like object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "FindByKeywords.py", line 21, in <module>
response = api.execute('findItemsByKeywords', request)
File "/usr/local/lib/python3.6/dist-packages/ebaysdk/connection.py", line 122, in execute
self.build_request(verb, data, verb_attrs, files)
File "/usr/local/lib/python3.6/dist-packages/ebaysdk/connection.py", line 162, in build_request
self.request = request.prepare()
File "/usr/lib/python3/dist-packages/requests/models.py", line 259, in prepare
hooks=self.hooks,
File "/usr/lib/python3/dist-packages/requests/models.py", line 306, in prepare
self.prepare_headers(headers)
File "/usr/lib/python3/dist-packages/requests/models.py", line 440, in prepare_headers
check_header_validity(header)
File "/usr/lib/python3/dist-packages/requests/utils.py", line 872, in check_header_validity
"bytes, not %s" % (name, value, type(value)))
requests.exceptions.InvalidHeader: Value for header {X-EBAY-SOA-SECURITY-APPNAME: None} must be of
type str or bytes, not <class 'NoneType'>
有谁知道如何阻止这种情况发生? ebay.yaml
文件包含我所有不同 API 的所有应用程序密钥,包括令牌。 app-id 存在于文件中,这很奇怪,因为异常表明APPNAME
在文件中存在时设置为None
。
作为参考,该程序以及ebay.yaml
文件位于存储库ebay
,该存储库位于我最初从 GitHub 获得的ebaysdk-python
存储库中。 ebaysdk-python
存储在适用于 Windows 的 Ubuntu Linux shell 的系统根目录中。 我正在使用的程序:
#!/usr/bin/python3
from ebaysdk.finding import Connection as Finding
#import os
#import sys
api = Finding(domain = 'svcs.sandbox.ebay.com', config_file = 'ebay.yaml', siteid = 'EBAY-US', debug = True)
request = {
'keywords': 'buffalo nickel coin',
'itemFilter': [
{'name': 'condition', 'value': 'new'}
],
'paginationInput': {
'entriesPerPage': 10,
'pageNumber': 1
},
'sortOrder': 'PricePlusShippingLowest'
}
response = api.execute('findItemsByKeywords', request)
results = open('/mnt/c/Users/iamno/Desktop/SearchResults.txt', 'w')
for item in response.reply.searchResult.item:
results.write(item.title + "\n")
results.close()
如果我将config_file
设置为None
并显式地将我的 app-id 传递到appid
参数中,则程序可以正常工作。 ebay.yaml
只是没有被正确识别。
这是因为默认的 'ebay.yaml' 没有 sanbox 域(svcs.ebay.com 是 prod 域)
只需将其添加到 yaml 文件中
svcs.sandbox.ebay.com:
appid: ENTER_YOUR_APPID_HERE
以下对我有用:
from ebaysdk.finding import Connection as Finding
yaml_path='C:/Users/Public/ebay/eBay_API/ebay_1.yaml' #path: yaml file location
api = Finding(config_file=yaml_path, siteid='EBAY-US')
request = {
'keywords': 'buffalo nickel coin',
'itemFilter': [
{'name': 'condition', 'value': 'new'}
],
'paginationInput': {
'entriesPerPage': 10,
'pageNumber': 1
},
'sortOrder': 'PricePlusShippingLowest'
}
response = api.execute('findItemsByKeywords', request)
print(response.reply.paginationOutput)
// {'pageNumber': '1', 'entriesPerPage': '10', 'totalPages': '982', 'totalEntries': '9813'}
更多与 eBay API 相关的细节: https : //github.com/Brat-Pit/eBay
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.