terricain / aioboto3

Wrapper to use boto3 resources with the aiobotocore async backend
Apache License 2.0
732 stars 75 forks source link

TypeError: __init__() got an unexpected keyword argument 'verify_ssl' #237

Closed Tears closed 3 years ago

Tears commented 3 years ago

Description

I have the following code:

async def upload_file(file, file_name):

    extension = os.path.splitext(file_name)[1]
    object_name = str(uuid.uuid4()) + extension

    bucket = os.environ['AWS_BUCKET_NAME']

    # Upload the file
    session = aioboto3.Session()
    async with session.resource("s3") as s3:
        try:
            response = await s3.upload_fileobj(file, bucket, object_name)
            tup = (True, object_name)
        except Exception as e:
            print(e)
            tup = (False, file_name)

    return tup

When executing this function, the following exception is raised:

File "/Users/user/.local/share/virtualenvs/api-gYx04z5g/lib/python3.9/site-packages/aiobotocore/endpoint.py", line 307, in create_endpoint
    connector = aiohttp.TCPConnector(
TypeError: __init__() got an unexpected keyword argument 'verify_ssl'

This is the output of my pip freeze:

aioboto3==9.2.0
aiobotocore==1.3.3
aiohttp==4.0.0a1
aioitertools==0.8.0
alembic==1.6.5
appdirs==1.4.4
asgiref==3.4.1
async-timeout==3.0.1
asyncpg==0.24.0
attrs==21.2.0
bcrypt==3.2.0
black==21.7b0
boto3==1.17.106
botocore==1.20.106
certifi==2021.5.30
cffi==1.14.6
chardet==3.0.4
charset-normalizer==2.0.3
click==8.0.1
colorful==0.6.0a1
cryptography==3.4.8
databases==0.5.0
dnspython==2.1.0
ecdsa==0.18.0b1
email-validator==1.1.3
fastapi==0.68.1
fastapi-permissions==0.2.7
FastAPI-SQLAlchemy==0.2.1
greenlet==1.1.1
h11==0.12.0
idna==3.2
iniconfig==1.1.1
isort==5.9.2
jmespath==0.10.0
Mako==1.1.5
MarkupSafe==2.0.1
multidict==4.7.6
mypy-extensions==0.4.3
packaging==21.0
passlib==1.7.4
pathspec==0.9.0
pluggy==1.0.0.dev0
prettyprinter==0.18.0
psycopg2-binary==2.9.1
py==1.10.0
pyasn1==0.4.8
pycparser==2.20
pydantic==1.8.2
Pygments==2.10.0
pyparsing==3.0.0b2
pytest==6.2.4
python-dateutil==2.8.2
python-dotenv==0.19.0
python-editor==1.0.4
python-http-client==3.3.2
python-jose==3.3.0
python-multipart==0.0.5
pytz==2021.1
regex==2021.7.6
requests==2.26.0
rsa==4.7.2
s3transfer==0.4.2
sendgrid==6.8.1
six==1.16.0
SQLAlchemy==1.4.23
starkbank-ecdsa==1.1.1
starlette==0.14.2
toml==0.10.2
tomli==1.1.0
typing-extensions==3.10.0.1
urllib3==1.26.6
uvicorn==0.15.0
wrapt==1.13.0rc3
yarl==1.6.3

Is this a bug in this package or are we doing something wrong? Thanks.

terricain commented 3 years ago

I can't reproduce it with

import asyncio
import aioboto3
import io

async def main():
    session = aioboto3.Session()
    async with session.resource("s3") as s3:
        fileobj = io.BytesIO(b'test')
        await s3.upload_fileobj(fileobj, 'aioboto3-test-bucket', 'test1')

asyncio.run(main())

As that returns AttributeError: 's3.ServiceResource' object has no attribute 'upload_fileobj' If I change it to use session.client I do indeed get the same error. I will look into this, its entirely possible that if I bump the aiobotocore version aioboto3 depends on, that would resolve it.

Tears commented 3 years ago

Thank you so much for your fast reply.

terricain commented 3 years ago

The problem comes from running aiohttp==4.0.0a1 which is an alpha package, the latest non-alpha is 3.7.4post0. Arguably this is an aiobotocore issue, maybe not yet, but when 4.0.0 lands it'll probably become one. I'll go raise an issue over there, for now, downgrade to aiohttp==3.7.4post0

Tears commented 3 years ago

The problem comes from running aiohttp==4.0.0a1 which is an alpha package, the latest non-alpha is 3.7.4post0. Arguably this is an aiobotocore issue, maybe not yet, but when 4.0.0 lands it'll probably become one. I'll go raise an issue over there, for now, downgrade to aiohttp==3.7.4post0

Thank you for your instructions. I have done that, and I'm now receiving the following exception:

    response = await s3.upload_fileobj(file, bucket, object_name)
AttributeError: 's3.ServiceResource' object has no attribute 'upload_fileobj'

Would you be so kind to assist me once more? Thanks.

terricain commented 3 years ago

Change async with session.resource("s3") as s3 to async with session.client("s3") as s3

Tears commented 3 years ago

Thank you!