簡體   English   中英

eBay Python 查找 API 中的身份驗證錯誤

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM