skip to Main Content

I’m trying to use the ebay.yaml file to quickly pass my application keys (specifically my app-id) into the Finding API. However, even though the file is in the same directory as the program, it throws this exception every time I ran the program:

    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'> 

Would anyone know how to stop this from happening? The ebay.yaml file contains all of my application keys for all the different APIs including the tokens. The app-id is present within the file which is strange since the exception says that the APPNAME is set to None when it is present within the file.

For reference, the program, as well as the ebay.yaml file, is in a repository ebay which is within the ebaysdk-python repository I originally got from GitHub. The ebaysdk-python is stored in the system root directory of an Ubuntu Linux shell for Windows.
The program I’m using:

#!/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()

If I set config_file to None and explicitly pass in my app-id into the appid parameter, the program works. The ebay.yaml is just not being recognized properly.

2

Answers


  1. Below works for me:

    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’}

    More details connected to eBay API: https://github.com/Brat-Pit/eBay

    Login or Signup to reply.
  2. It is because the default ‘ebay.yaml’ doesn’t have the sanbox domain (svcs.ebay.com is the prod domain)

    Just add this in yaml file

    svcs.sandbox.ebay.com:
        appid: ENTER_YOUR_APPID_HERE
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search