cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

python - ebaysdk - Shopping API, Token not found, yet included in YAML

using the Shopping API Class, I've constructed the YAML as so :

 

open.api.ebay.com:
iaf_token: myToken
appid: myappid
certid : mycertid
version: 799

 

Yet I received this error:

 

'GetSingleItem: Class: RequestError, Severity: Error, Code: 1.33, Token not available in request. Token not available in request. Please specify a valid token as HTTP header.'
{'Timestamp': '2023-03-21T23:08:05.329Z', 'Ack': 'Failure', 'Errors': {'ShortMessage': 'Token not available in request.', 'LongMessage': 'Token not available in request. Please specify a valid token as HTTP header.', 'ErrorCode': '1.33', 'SeverityCode': 'Error', 'ErrorClassification': 'RequestError'}, 'Build': 'E1199_CORE_APILW_19146596_R1', 'Version': '1199'}

 

I've included iaf_token as per the git hub documentation of the shopping API (https://github.com/timotheus/ebaysdk-python/tree/master/ebaysdk/shopping). 


Would anyone be able to help?

Message 1 of 6
latest reply
1 BEST ANSWER

Accepted Solutions

python - ebaysdk - Shopping API, Token not found, yet included in YAML

hmmm,

api = Shopping(config_file='./ebay.yaml', siteid='EBAY-GB',https=True,warnings=True,debug=True)

works fine for me.

Are there any typos in iaf_token:  in the yaml file? such as iaf-token? It will set a variable for anything listed in the yaml, used or not, even if it is incorrect. s.request.headers is another place to look to verify. Could also be something in how things are imported.

 

These are all working for me:

sdk import

 

from ebaysdk.shopping import Connection
s = Connection(config_file='./ebay.yaml', siteid='EBAY-GB',https=True,warnings=True,debug=True)
xml="""
  <ItemID>SOMEITEMID</ItemID>
"""
r = s.execute("GetSingleItem", data=xml)

 

as well as requests directly:

 

import requests

headers = {
"X-EBAY-API-IAF-TOKEN":"YOURIAFTOKEN"
}

url = "https://open.api.ebay.com/shopping?callname=GetSingleItem&version=1199&ItemID=SOMEITEMID"

r = requests.Request(method="GET", headers=headers, url=url)
pr = r.prepare()
ses = requests.Session()
res = ses.send(pr)
print(res.content)

 

 

as well as requests directly 2:

 

import requests

headers = {
"X-EBAY-API-VERSION": "1199",
"X-EBAY-API-SITE-ID": "EBAY-GB",
"X-EBAY-API-REQUEST-ENCODING": "XML",
"Content-Type": "text/xml",
"X-EBAY-API-CALL-NAME": "GetSingleItem",
"X-EBAY-API-IAF-TOKEN":"YOURIAFTOKEN"
}

xml="""<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<GetSingleItemRequest xmlns=\"urnapis:eBLBaseComponents\">
  <ItemID>SOMEITEMID</ItemID>
</GetSingleItemRequest>
"""

url = "https://open.api.ebay.com/shopping"

r = requests.Request(method="POST", headers=headers, data=xml.encode("UTF-8"), url=url)
pr = r.prepare()
ses = requests.Session()
res = ses.send(pr)
print(res.content)

 

 

 

 

View Best Answer in original post

Message 5 of 6
latest reply
5 REPLIES 5

python - ebaysdk - Shopping API, Token not found, yet included in YAML

If this is the instruction you are trying:

 

s = Connection(config_file=os.environ.get('EBAY_YAML'))

 

That is attempting to load something set to an environment variable of your host OS (differing depending on the OS you are using, you would need to figure out how to load the file contents to that variable prior to that line).

 

You could instead try to load the file directly:

 

s = Connection(config_file="./ebay.yaml")

 

the above being a relative path to where your python is working from.

 

you can also look at the config.values on the s object to see what has been loaded

 

s.config.values

or

print(s.config.values)

 

Message 2 of 6
latest reply

python - ebaysdk - Shopping API, Token not found, yet included in YAML

@five_notch_trading_post Thanks for the reply!

I'm constructing the call as per the ebaysdk Shopping class:

      api = Shopping(config_file='./ebay.yaml', siteid='EBAY-GB',https=True,warnings=True,debug=True)
 
I load the file directly, and it still triggers the error.
 
 
 
Message 3 of 6
latest reply

python - ebaysdk - Shopping API, Token not found, yet included in YAML

When I hard code the iaf token in the headers of the shopping __init__.py file (I know, not the best practice) the call works and returns data!

 

The __init__ file doesn't pick up the iaf token correctly from the yaml file.

I can use this: s.config.values and it returns the variables, including the iaf token from the yaml file. But the __init__ file doesn't pick it up. 

 

Interesting. I will highlight this in the git hub issues tab for the ebaysdk repo.

Message 4 of 6
latest reply

python - ebaysdk - Shopping API, Token not found, yet included in YAML

hmmm,

api = Shopping(config_file='./ebay.yaml', siteid='EBAY-GB',https=True,warnings=True,debug=True)

works fine for me.

Are there any typos in iaf_token:  in the yaml file? such as iaf-token? It will set a variable for anything listed in the yaml, used or not, even if it is incorrect. s.request.headers is another place to look to verify. Could also be something in how things are imported.

 

These are all working for me:

sdk import

 

from ebaysdk.shopping import Connection
s = Connection(config_file='./ebay.yaml', siteid='EBAY-GB',https=True,warnings=True,debug=True)
xml="""
  <ItemID>SOMEITEMID</ItemID>
"""
r = s.execute("GetSingleItem", data=xml)

 

as well as requests directly:

 

import requests

headers = {
"X-EBAY-API-IAF-TOKEN":"YOURIAFTOKEN"
}

url = "https://open.api.ebay.com/shopping?callname=GetSingleItem&version=1199&ItemID=SOMEITEMID"

r = requests.Request(method="GET", headers=headers, url=url)
pr = r.prepare()
ses = requests.Session()
res = ses.send(pr)
print(res.content)

 

 

as well as requests directly 2:

 

import requests

headers = {
"X-EBAY-API-VERSION": "1199",
"X-EBAY-API-SITE-ID": "EBAY-GB",
"X-EBAY-API-REQUEST-ENCODING": "XML",
"Content-Type": "text/xml",
"X-EBAY-API-CALL-NAME": "GetSingleItem",
"X-EBAY-API-IAF-TOKEN":"YOURIAFTOKEN"
}

xml="""<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<GetSingleItemRequest xmlns=\"urnapis:eBLBaseComponents\">
  <ItemID>SOMEITEMID</ItemID>
</GetSingleItemRequest>
"""

url = "https://open.api.ebay.com/shopping"

r = requests.Request(method="POST", headers=headers, data=xml.encode("UTF-8"), url=url)
pr = r.prepare()
ses = requests.Session()
res = ses.send(pr)
print(res.content)

 

 

 

 

Message 5 of 6
latest reply

python - ebaysdk - Shopping API, Token not found, yet included in YAML

I reverted the changes to the __init__ file of the shopping API class, and now it works... I really don't know how or why but it works.

 

I had no typos before, it just was giving me that token error. weird. I might have been doing something wrong but don't know what.

 

It works now. Thanks, @five_notch_trading_post  for the time in assisting here.

Message 6 of 6
latest reply