aio-libs / aiobotocore

asyncio support for botocore library using aiohttp

Home Page:https://aiobotocore.rtfd.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: object dict can't be used in 'await' expression

tekumara opened this issue · comments

Describe the bug

When AWS credentials exist but are stale, eg:

❯  echo $AWS_CREDENTIAL_EXPIRATION
AWS_CREDENTIAL_EXPIRATION=2023-06-28T10:44:05Z

Attempt to access s3, eg:

❯ python
Python 3.11.4 (main, Jun 15 2023, 07:55:38) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import s3fs
>>> s3 = s3fs.S3FileSystem()
>>> s3.ls("s3://ai2-public-datasets/")
Refreshing temporary credentials failed during mandatory refresh period.
Traceback (most recent call last):
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/credentials.py", line 327, in _protected_refresh
    metadata = await self._refresh_using()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object dict can't be used in 'await' expression
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/fsspec/asyn.py", line 121, in wrapper
    return sync(self.loop, func, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/fsspec/asyn.py", line 106, in sync
    raise return_result
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/fsspec/asyn.py", line 61, in _runner
    result[0] = await coro
                ^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/s3fs/core.py", line 956, in _ls
    files = await self._lsdir(path, refresh, versions=versions)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/s3fs/core.py", line 693, in _lsdir
    async for c in self._iterdir(
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/s3fs/core.py", line 743, in _iterdir
    async for i in it:
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/paginate.py", line 30, in __anext__
    response = await self._make_request(current_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/client.py", line 361, in _make_api_call
    http, parsed_response = await self._make_request(
                            ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/client.py", line 386, in _make_request
    return await self._endpoint.make_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/endpoint.py", line 96, in _send_request
    request = await self.create_request(request_dict, operation_model)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/endpoint.py", line 84, in create_request
    await self._event_emitter.emit(
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/hooks.py", line 66, in _emit
    response = await resolve_awaitable(handler(**kwargs))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/_helpers.py", line 15, in resolve_awaitable
    return await obj
           ^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/signers.py", line 24, in handler
    return await self.sign(operation_name, request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/signers.py", line 73, in sign
    auth = await self.get_auth_instance(**kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/signers.py", line 147, in get_auth_instance
    await self._credentials.get_frozen_credentials()
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/credentials.py", line 358, in get_frozen_credentials
    await self._refresh()
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/credentials.py", line 312, in _refresh
    await self._protected_refresh(
  File "/Users/tekumara/.virtualenvs/tmp-242ef4b41132cb1/lib/python3.11/site-packages/aiobotocore/credentials.py", line 327, in _protected_refresh
    metadata = await self._refresh_using()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object dict can't be used in 'await' expression

Checklist

  • I have reproduced in environment where pip check passes without errors
  • I have provided pip freeze results
  • I have provided sample code or detailed way to reproduce
  • I have tried the same code in botocore to ensure this is an aiobotocore specific issue
  • I have tried similar code in aiohttp to ensure this is is an aiobotocore specific issue
  • I have checked the latest and older versions of aiobotocore/aiohttp/python to see if this is a regression / injection

pip freeze results

❯ pip freeze
aiobotocore==2.5.1
aiohttp==3.8.4
aioitertools==0.11.0
aiosignal==1.3.1
async-timeout==4.0.2
attrs==23.1.0
botocore==1.29.161
charset-normalizer==3.1.0
frozenlist==1.3.3
fsspec==2023.6.0
idna==3.4
jmespath==1.0.1
multidict==6.0.4
python-dateutil==2.8.2
s3fs==2023.6.0
six==1.16.0
urllib3==1.26.16
wrapt==1.15.0
yarl==1.9.2

Environment:

  • Python Version: 3.11
  • OS name and version: darwin

Additional context

botocore fails on stale credentials with the more informative error message:

RuntimeError: Credentials were refreshed, but the refreshed credentials are still expired.