aio-libs / aiobotocore

asyncio support for botocore library using aiohttp
https://aiobotocore.rtfd.io
Apache License 2.0
1.14k stars 179 forks source link

AttributeError: 'S3' object has no attribute 'upload_file'" when calling upload_file on s3 client #1071

Closed mastern2k3 closed 7 months ago

mastern2k3 commented 7 months ago

Describe the bug I'm creating an s3 client just as described in the examples, and using upload_file() which is a boto s3 client command and described in the aiobotocore_s3 stubs and I'm getting an error saying the function doesn't exist.

Other functions like create_bucket work.

My code:

session = get_session()
async with session.create_client('s3') as s3_client:
    await s3_client.upload_file(
        Filename=filename,
        Bucket=bucket_name,
        Key=key,
    )

From stubs:

    async def upload_file(
        self,
        Filename: str,
        Bucket: str,
        Key: str,
        ExtraArgs: Optional[Dict[str, Any]] = ...,
        Callback: Optional[Callable[..., Any]] = ...,
        Config: Optional[TransferConfig] = ...,
    ) -> None:
        """
        Upload a file to an S3 object.

        [Show boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.upload_file)
        [Show types-aiobotocore documentation](https://youtype.github.io/types_aiobotocore_docs/types_aiobotocore_s3/client/#upload_file)
        """

Checklist

pip freeze results

aio-pika==8.3.0
aiobotocore==2.9.0
aiohttp==3.9.1
aioitertools==0.11.0
aiormq==6.6.4
aiosignal==1.3.1
antlr4-python3-runtime==4.9.3
anyio==4.2.0
arrow==1.3.0
async-timeout==4.0.3
attrs==23.2.0
av==11.0.0
aws-sam-cli==1.107.0
aws-sam-translator==1.83.0
aws_lambda_builders==1.45.0
backports.zoneinfo==0.2.1
binaryornot==0.4.4
blinker==1.7.0
boto3==1.33.13
boto3-stubs==1.34.12
botocore==1.33.13
botocore-stubs==1.34.18
certifi==2023.11.17
cffi==1.16.0
cfn-lint==0.83.8
chardet==5.2.0
charset-normalizer==3.3.2
chevron==0.14.0
click==8.1.7
cookiecutter==2.5.0
cryptography==41.0.7
dateparser==1.2.0
decorator==5.1.1
dependency-injector==4.41.0
docker==7.0.0
exceptiongroup==1.2.0
Faker==17.6.0
Flask==3.0.0
frozenlist==1.4.1
gql==2.0.0
graphql-core==2.3.2
h11==0.14.0
httpcore==0.17.3
httpx==0.24.1
idna==3.6
importlib-metadata==7.0.1
importlib-resources==6.1.1
iniconfig==2.0.0
itsdangerous==2.1.2
Jinja2==3.1.3
jmespath==1.0.1
jschema-to-python==1.2.3
jsonpatch==1.33
jsonpickle==3.0.2
jsonpointer==2.4
jsonschema==4.20.0
jsonschema-specifications==2023.12.1
junit-xml==1.9
loguru==0.6.0
markdown-it-py==3.0.0
MarkupSafe==2.1.3
mdurl==0.1.2
mpmath==1.3.0
multidict==6.0.4
mypy-boto3-apigateway==1.34.0
mypy-boto3-autoscaling==1.34.0
mypy-boto3-cloudformation==1.34.0
mypy-boto3-dynamodb==1.34.0
mypy-boto3-ec2==1.34.17
mypy-boto3-ecr==1.34.0
mypy-boto3-iam==1.34.8
mypy-boto3-kinesis==1.34.0
mypy-boto3-lambda==1.34.0
mypy-boto3-s3==1.34.14
mypy-boto3-schemas==1.34.0
mypy-boto3-secretsmanager==1.34.17
mypy-boto3-signer==1.34.0
mypy-boto3-sqs==1.34.0
mypy-boto3-stepfunctions==1.34.0
mypy-boto3-sts==1.34.0
mypy-boto3-transcribe==1.34.0
mypy-boto3-xray==1.34.0
networkx==3.1
numpy==1.24.4
omegaconf==2.3.0
packaging==23.2
pamqp==3.2.1
pbr==6.0.0
pkgutil_resolve_name==1.3.10
pluggy==1.3.0
praat-parselmouth==0.4.3
promise==2.3
py==1.11.0
pycparser==2.21
pydantic==1.10.13
pydash==5.1.2
Pygments==2.17.2
pyOpenSSL==23.3.0
pytest==7.4.4
pytest-asyncio==0.23.3
pytest-docker==2.0.1
python-dateutil==2.8.2
python-slugify==8.0.1
pytz==2023.3.post1
PyYAML==6.0.1
referencing==0.32.1
regex==2023.12.25
requests==2.31.0
requests-aws4auth==1.2.3
retry==0.9.2
rich==13.7.0
rpds-py==0.17.1
ruamel.yaml==0.18.5
ruamel.yaml.clib==0.2.8
Rx==1.6.3
s3transfer==0.8.2
sarif-om==1.0.4
sentry-sdk==1.39.2
six==1.16.0
sniffio==1.3.0
sympy==1.12
text-unidecode==1.3
tomli==2.0.1
tomlkit==0.12.3
tqdm==4.66.1
types-aiobotocore==2.9.0
types-aiobotocore-s3==2.9.0
types-awscrt==0.20.0
types-python-dateutil==2.8.19.20240106
types-s3transfer==0.10.0
typing_extensions==4.9.0
tzlocal==5.2
Unidecode==1.3.8
urllib3==1.26.18
watchdog==3.0.0
webrtcvad==2.0.10
Werkzeug==3.0.1
wrapt==1.16.0
yarl==1.9.4
zipp==3.17.0

Environment:

mastern2k3 commented 7 months ago

I can't use put_object, e.g.:

with open('file.txt') as file_handle:
    client.put_object(Bucket=bucket, Key=key, Body=file_handle)

Because i get:

E           botocore.exceptions.ClientError: An error occurred (413) when calling the PutObject operation: Request Entity Too Large
jakob-keller commented 7 months ago

The S3 upload_file operation is not part of aiobotocore, nor botocore. It is offered as part of the boto3 library. You might want to check out https://github.com/terrycain/aioboto3 for an async port.