tkem/cachetools

Cachetools error - Python\lib\site-packages\cachetools_init_.py", line 68, in getitem return self.__data[key] KeyError: 'role_

Closed this issue · 1 comments

I have confirmed that this python library is working with the exact same code on another PC however on one of my workstations I am unsure why I am receiving the following error.

I have attempted to uninstall all of the site packages thinking that maybe it was a bug of some kind. However this still doesn't fix my issue either. I'm really lost and could use some guidance....

### Here is my code putting in "*****" to protect the credentials:

from sp_api.base import Marketplaces
from sp_api.api import Orders
from datetime import datetime, timedelta, date

credentials = dict(
    refresh_token='Atzr|********************************************UXryc',  # From Seller central under Authorise -> Refresh Token
    lwa_app_id='amzn1.application-oa2-**************************83f',  # From Seller Central, named CLIENT IDENTIFIER on website.
    lwa_client_secret='26c*********************756e',  # From Seller Central, named CLIENT SECRET on website.
    aws_access_key='AK***********UX',  # From AWS IAM Setup
    aws_secret_key='S5***************MhF',  # From AWS IAM Setup
    `role_arn='arn:aws:iam::************:role/SellingPartnerAPI_Role'`  #arn:aws:iam::1234567890:role/SellingPartnerAPIRole
)


order_client = Orders(credentials=credentials, marketplace=Marketplaces.US)
order = order_client.get_order('113-2528766-2545802')
print(order) # `order` is an `ApiResponse`
print(order.payload) # `payload` contains the original response

As you can see this is using the python-amazon-sp-api python library which utilizes cache tools. Since this is not working only on one of my workstations, I would assume that there is some environment variable I need to clear/fix on my machine. However, I'm unsure where cache tools is trying to obtain this data to know what I should do to fix this. Any ideas/guidance/troubleshooting steps would be greatly appreciated!

### Here is what I have already tired:
-Python 3.9.7 uninstalled and reinstalled
-python-amazon-sp-api(with all required site packages ie cachetools) uninstalled and reinstalled
-C Drive temp files cleared

### Here is the error being received:

Traceback (most recent call last):
File "F:\Python\lib\site-packages\cachetools_init_.py", line 68, in getitem
return self.__data[key]
KeyError: 'role_74fc5af19254feae9a64bd3255ef2ac6'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "F:\Python\lib\site-packages\sp_api\base\client.py", line 112, in role
role = role_cache[cache_key]
File "F:\Python\lib\site-packages\cachetools_init_.py", line 418, in getitem
return cache_getitem(self, key)
File "F:\Python\lib\site-packages\cachetools_init_.py", line 70, in getitem
return self.missing(key)
File "F:\Python\lib\site-packages\cachetools_init_.py", line 97, in missing
raise KeyError(key)
KeyError: 'role_74fc5af19254feae9a64bd3255ef2ac6'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\Users\GlowSharpie\Desktop\Python Scripts\Barcode Creation\FBA\SP API\SP_API_Test3.py", line 16, in
order = order_client.get_order('113-2528766-2545802')
File "F:\Python\lib\site-packages\sp_api\base\helpers.py", line 20, in wrapper
return function(*args, **kwargs)
File "F:\Python\lib\site-packages\sp_api\api\orders\orders.py", line 95, in get_order
return self._request(fill_query_params(kwargs.pop('path'), order_id), params={**kwargs}, add_marketplace=False)
File "F:\Python\lib\site-packages\sp_api\base\client.py", line 153, in _request
auth=self._sign_request(),
File "F:\Python\lib\site-packages\sp_api\base\client.py", line 122, in _sign_request
role = self.role
File "F:\Python\lib\site-packages\sp_api\base\client.py", line 114, in role
role = self.set_role(cache_key)
File "F:\Python\lib\site-packages\sp_api\base\client.py", line 81, in set_role
role = self.boto3_client.assume_role(
File "F:\Python\lib\site-packages\botocore\client.py", line 530, in _api_call
return self._make_api_call(operation_name, kwargs)
File "F:\Python\lib\site-packages\botocore\client.py", line 943, in _make_api_call
http, parsed_response = self._make_request(
File "F:\Python\lib\site-packages\botocore\client.py", line 966, in _make_request
return self._endpoint.make_request(operation_model, request_dict)
File "F:\Python\lib\site-packages\botocore\endpoint.py", line 119, in make_request
return self._send_request(request_dict, operation_model)
File "F:\Python\lib\site-packages\botocore\endpoint.py", line 202, in _send_request
while self._needs_retry(
File "F:\Python\lib\site-packages\botocore\endpoint.py", line 354, in _needs_retry
responses = self._event_emitter.emit(
File "F:\Python\lib\site-packages\botocore\hooks.py", line 412, in emit
return self._emitter.emit(aliased_event_name, **kwargs)
File "F:\Python\lib\site-packages\botocore\hooks.py", line 256, in emit
return self._emit(event_name, kwargs)
File "F:\Python\lib\site-packages\botocore\hooks.py", line 239, in _emit
response = handler(**kwargs)
File "F:\Python\lib\site-packages\botocore\retryhandler.py", line 207, in call
if self._checker(**checker_kwargs):
File "F:\Python\lib\site-packages\botocore\retryhandler.py", line 284, in call
should_retry = self._should_retry(
File "F:\Python\lib\site-packages\botocore\retryhandler.py", line 320, in _should_retry
return self._checker(attempt_number, response, caught_exception)
File "F:\Python\lib\site-packages\botocore\retryhandler.py", line 363, in call
checker_response = checker(
File "F:\Python\lib\site-packages\botocore\retryhandler.py", line 247, in call
return self._check_caught_exception(
File "F:\Python\lib\site-packages\botocore\retryhandler.py", line 416, in _check_caught_exception
raise caught_exception
File "F:\Python\lib\site-packages\botocore\endpoint.py", line 281, in _do_get_response
http_response = self._send(request)
File "F:\Python\lib\site-packages\botocore\endpoint.py", line 377, in _send
return self.http_session.send(request)
File "F:\Python\lib\site-packages\botocore\httpsession.py", line 484, in send
raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://sts.us.amazonaws.com/"
PS C:\Users\GlowSharpie\Desktop\Python Scripts\Barcode Creation\FBA\SP API>
tkem commented

Sorry, but I don't know about python-amazon-sp-api. You're probably better off posting an issue there...