fastapi-storages icon indicating copy to clipboard operation
fastapi-storages copied to clipboard

Recursion problem

Open R1Sen007 opened this issue 5 months ago • 0 comments

Hi! I am newbee at FastApi and s3, but when i send file (from fastapi Swagger) to my endpoint, i have next traceback:

 ...
  File "/usr/local/Cellar/[email protected]/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/email/message.py", line 459, in <listcomp>
    return [(k, self.policy.header_fetch_parse(k, v))
  File "/usr/local/Cellar/[email protected]/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/email/_policybase.py", line 316, in header_fetch_parse
    return self._sanitize_header(name, value)
  File "/usr/local/Cellar/[email protected]/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/email/_policybase.py", line 287, in _sanitize_header
    if _has_surrogates(value):
  File "/usr/local/Cellar/[email protected]/3.9.19/Frameworks/Python.framework/Versions/3.9/lib/python3.9/email/utils.py", line 57, in _has_surrogates
    s.encode()
RecursionError: maximum recursion depth exceeded while calling a Python object

I can't find any problem because recursion overflow my terminal and i see only this repeating traceback.

STORAGE:

from fastapi_storages import S3Storage
from fastapi_storages.integrations.sqlalchemy import FileType


class PrivateAssetS3Storage(S3Storage):
    AWS_ACCESS_KEY_ID = "some info here"
    AWS_SECRET_ACCESS_KEY = "some info here"
    AWS_S3_BUCKET_NAME = "some-info-here"
    AWS_S3_ENDPOINT_URL = "some.info.here"
    AWS_DEFAULT_ACL = "public-read"
    AWS_QUERYSTRING_AUTH = True
    AWS_S3_USE_SSL = False


storage = PrivateAssetS3Storage()

ENDPOINT:

from app.services.s3storage import storage
...
@router.post(
    '/tests3_upload'
)
def create_upload_file(file: UploadFile):
    key = storage.write(file=file.file, name='testFile')
    url = storage.get_path(name=key)
    print(url)
    return {'url': url}

R1Sen007 avatar Sep 26 '24 10:09 R1Sen007