我在Heroku上部署了Python Flask网络应用程序,并且一切正常,除了尝试将文件上传到Amazon S3 Bucket时。
我尝试在Heroku网站和终端上手动将S3键设置为Config Vars,但无济于事。
2019-07-17T19:23:49.720789+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/client.py", line 357, in _api_call
2019-07-17T19:23:49.720791+00:00 app[web.1]: return self._make_api_call(operation_name, kwargs)
2019-07-17T19:23:49.720793+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/client.py", line 648, in _make_api_call
2019-07-17T19:23:49.720795+00:00 app[web.1]: operation_model, request_dict, request_context)
2019-07-17T19:23:49.720797+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/client.py", line 667, in _make_request
2019-07-17T19:23:49.720799+00:00 app[web.1]: return self._endpoint.make_request(operation_model, request_dict)
2019-07-17T19:23:49.720801+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/endpoint.py", line 102, in make_request
2019-07-17T19:23:49.720803+00:00 app[web.1]: return self._send_request(request_dict, operation_model)
2019-07-17T19:23:49.720805+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/endpoint.py", line 132, in _send_request
2019-07-17T19:23:49.720807+00:00 app[web.1]: request = self.create_request(request_dict, operation_model)
2019-07-17T19:23:49.720809+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/endpoint.py", line 116, in create_request
2019-07-17T19:23:49.720811+00:00 app[web.1]: operation_name=operation_model.name)
2019-07-17T19:23:49.720813+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/hooks.py", line 356, in emit
2019-07-17T19:23:49.720815+00:00 app[web.1]: return self._emitter.emit(aliased_event_name, **kwargs)
2019-07-17T19:23:49.720817+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/hooks.py", line 228, in emit
2019-07-17T19:23:49.720819+00:00 app[web.1]: return self._emit(event_name, kwargs)
2019-07-17T19:23:49.720821+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/hooks.py", line 211, in _emit
2019-07-17T19:23:49.720823+00:00 app[web.1]: response = handler(**kwargs)
2019-07-17T19:23:49.720825+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/signers.py", line 90, in handler
2019-07-17T19:23:49.720827+00:00 app[web.1]: return self.sign(operation_name, request)
2019-07-17T19:23:49.720829+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/signers.py", line 157, in sign
2019-07-17T19:23:49.720832+00:00 app[web.1]: auth.add_auth(request)
2019-07-17T19:23:49.720834+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/auth.py", line 425, in add_auth
2019-07-17T19:23:49.720836+00:00 app[web.1]: super(S3SigV4Auth, self).add_auth(request)
2019-07-17T19:23:49.720838+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/botocore/auth.py", line 357, in add_auth
2019-07-17T19:23:49.720840+00:00 app[web.1]: raise NoCredentialsError
2019-07-17T19:23:49.720847+00:00 app[web.1]: botocore.exceptions.NoCredentialsError: Unable to locate credentials
错误是“ botocore.exceptions.NoCredentialsError:无法找到凭据”,即使我在Flask应用程序中正确设置了S3密钥(在localhost上也可以正常使用)。
提前谢谢!
答案 0 :(得分:0)
对于那些遇到相同问题的人,我已经弄清楚了。因此,我最初在我的代码和Settings
上的Heroku中使用自定义变量名而不是标准名称AWS_ACCESS_KEY_ID
和AWS_SECRET_ACCESS_KEY
来设置S3存储桶的凭据。这有点受限制,但是为了使凭据正常工作,您必须将它们分别命名为AWS_ACCESS_KEY_ID
和AWS_SECRET_ACCESS_KEY
,然后现在一切都应该没问题了。