[英]Getting TypeError when trying to upload to s3 from heroku
Error: TypeError at /accounts/work_feed/upload/1 sequence item 0: expected str instance, NoneType found错误:/accounts/work_feed/upload/1 序列项 0 处的 TypeError:预期的 str 实例,未找到 NoneType
Im getting this error when I try to upload an image from my django app on heroku to an aws s3 bucket.当我尝试将图像从 heroku 上的 django 应用程序上传到 aws s3 存储桶时,出现此错误。
My settings.py looks like:我的 settings.py 看起来像:
ROOT_URLCONF = 'ClassTrail.urls'
DATABASES = {
'default': dj_database_url.config()
}
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = 'static/'
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
django_heroku.settings(locals())
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = os.environ.get('BUCKET_NAME')
S3_URL = 'https://%s.s3.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
AWS_QUERYSTRING_AUTH = False
(I cut out some irrelevant bits of settings.py) (我删掉了一些不相关的settings.py)
My app works perfectly with postgres and aws locally, but when I run the website on heroku, everything works except for uploading files to aws.我的应用程序在本地与 postgres 和 aws 完美配合,但是当我在 heroku 上运行网站时,除了将文件上传到 aws 之外,一切正常。
I have set environment variables on heroku using heroku config:set.我已经使用 heroku config:set 在 heroku 上设置了环境变量。
My bucket policy is:我的存储桶策略是:
{
"Version": "2012-10-17",
"Id": "Policy1648918943307",
"Statement": [
{
"Sid": "Stmt1648918911640",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::classtrailstorage/*"
}
]
}
and i have tried to set a cors with:我试图用以下方法设置 cors:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD",
"POST",
"PUT"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
Thank you for any help!感谢您的任何帮助!
Okay, so after hours of debugging and trying different methods to get it working, the issue was that I had set my heroku config vars as: AAWS_ACCESS_KEY_ID instead of AWS_ACCESS_KEY_ID.好的,经过数小时的调试并尝试不同的方法使其正常工作后,问题是我将 heroku 配置变量设置为:AAWS_ACCESS_KEY_ID 而不是 AWS_ACCESS_KEY_ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.