IBM / ibm-cos-sdk-python

ibm-cos-sdk-python
Apache License 2.0
46 stars 26 forks source link

'NoneType' object has no attribute 'token' #47

Closed roryodonnell closed 2 years ago

roryodonnell commented 2 years ago

Hitting an auth issue whilst checking for a COS bucket - I'm unsure if it's a self inflicted issue or not - please feel free to close if not due to COS SDK

Jan 31 12:25:01 dev-serv-upload-v2-6644c77cf6-xxcbx serv-upload-v2 Traceback (most recent call last):
  File "/home/fd4b/.local/lib/python3.8/site-packages/upload/cos.py", line 147, in _bucket_exists
    self._client.head_bucket(Bucket=cos_request.bucket_name)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/client.py", line 662, in _make_api_call
    http, parsed_response = self._make_request(
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/client.py", line 682, in _make_request
    return self._endpoint.make_request(operation_model, request_dict)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/endpoint.py", line 102, in make_request
    return self._send_request(request_dict, operation_model)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/endpoint.py", line 132, in _send_request
    request = self.create_request(request_dict, operation_model)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/endpoint.py", line 115, in create_request
    self._event_emitter.emit(event_name, request=request,
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/hooks.py", line 356, in emit
    return self._emitter.emit(aliased_event_name, **kwargs)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/hooks.py", line 228, in emit
    return self._emit(event_name, kwargs)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/hooks.py", line 211, in _emit
    response = handler(**kwargs)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/signers.py", line 90, in handler
    return self.sign(operation_name, request)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/signers.py", line 162, in sign
    auth.add_auth(request)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/auth.py", line 853, in add_auth
    self._inject_token_to_request(request)
  File "/home/fd4b/.local/lib/python3.8/site-packages/ibm_botocore/auth.py", line 865, in _inject_token_to_request
    request.headers['Authorization'] = ("Bearer %s" % self.credentials.token)
Jan 31 12:25:01 dev-serv-upload-v2-6644c77cf6-xxcbx serv-upload-v2 AttributeError: 'NoneType' object has no attribute 'token'
Jan 31 12:25:01 dev-serv-upload-v2-6644c77cf6-xxcbx serv-upload-v2 During handling of the above exception, another exception occurred:
Jan 31 12:25:01 dev-serv-upload-v2-6644c77cf6-xxcbx serv-upload-v2 Traceback (most recent call last):
  File "/home/fd4b/.local/lib/python3.8/site-packages/upload/vectordata_upload_handler.py", line 96, in post
    await self.processJob(job)
  File "/home/fd4b/.local/lib/python3.8/site-packages/upload/vectordata_upload_handler.py", line 115, in processJob
    await job.start()
  File "/home/fd4b/.local/lib/python3.8/site-packages/upload/vectordata_job.py", line 78, in start
    await self._cos_client.bucket_exists(self._cos_request)
  File "/home/fd4b/.local/lib/python3.8/site-packages/upload/cos.py", line 141, in bucket_exists
    return await self._bucket_exists(cos_request)
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/fd4b/.local/lib/python3.8/site-packages/upload/cos.py", line 154, in _bucket_exists
    raise CosException(msg)
upload.cos.CosException: COS bucket [agrotech-dev-agroqateam-onboarding] not found, failed with exception ['NoneType' object has no attribute 'token']
roryodonnell commented 2 years ago

@IBMeric - any insight would be greatly appreciated

roryodonnell commented 2 years ago

Must have been something to do with connection properties / service availability - seems all good now

roryodonnell commented 2 years ago

We never seemed to discover the original cause and now we are experiencing it again. It would be great if the sdk could provide further information why the credentials.token is not populated. It's most likely a service issue caused by IBM Cloud COS Auth servers

roryodonnell commented 2 years ago

Ok have finally discovered the cause. Our COS API key was not being seeding correctly from vault and thus was using an empty string when trying to connect.