gpt4 book ai didi

ubuntu - 如何使用 Boto3 修复 DynamoDB 的 "NoCredentialsError"

转载 作者:行者123 更新时间:2023-12-04 19:25:08 26 4
gpt4 key购买 nike

我目前正在使用 Flask 和 DynamoDB 创建一个 webapp。
但是,我目前遇到了一个非常奇怪的错误,我希望有人能够帮助我。
目前,当我在 Pycharm 中运行 Web 应用程序时,一切正常。
我能够从 DynamoDB 请求数据而没有任何问题或错误。
但是,当我在 Ubuntu 上使用 Python3 运行完全相同的文件时,我突然遇到了“NoCredentialsError”。
当我在 Pycharm 上运行完全相同的文件时,它工作正常,但由于某种原因,只有当我尝试在 Ubuntu 中测试它时,它才会给我这个错误。
导致此错误的函数很简单:


def selectItem(PK, SK):

dynamodb = boto3.resource('dynamodb', region_name="us-east-1")

table = dynamodb.Table('testDB')

response = table.get_item(
Key={
'PK': PK,
'SK': SK
}
)
return response
为了上下文和在测试时保持简单,我对表格和区域进行了编码。
以下是完整的 Traceback 以获取更多详细信息:

File "/home/testcode/.local/lib/python3.8/site-packages/flask/app.py", line 2095, in callreturn self.wsgi_app(environ, start_response)


File "/home/testcode/.local/lib/python3.8/site-packages/flask/app.py", line 2080, in wsgi_appresponse = self.handle_exception(e)


File "/home/testcode/.local/lib/python3.8/site-packages/flask/app.py", line 2077, in wsgi_appresponse = self.full_dispatch_request()


File "/home/testcode/.local/lib/python3.8/site-packages/flask/app.py", line 1525, in full_dispatch_requestrv = self.handle_user_exception(e)


File "/home/testcode/.local/lib/python3.8/site-packages/flask/app.py", line 1523, in full_dispatch_requestrv = self.dispatch_request()


File "/home/testcode/.local/lib/python3.8/site-packages/flask/app.py", line 1509, in dispatch_requestreturn self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)


File "/mnt/c/Users/Test/Desktop/Coding/TestCode/mainapp/webapp.py", line 139, in loginsession["farm"] = DynamoDB.selectItem("Users", session["email"])


File "/mnt/c/Users/Test/Desktop/Coding/TestCode/mainapp/DataBase/DynamoDB.py", line 147, in selectItemresponse = table.get_item(


File "/home/testcode/.local/lib/python3.8/site-packages/boto3/resources/factory.py", line 580, in do_actionresponse = action(self, *args, **kwargs)


File "/home/testcode/.local/lib/python3.8/site-packages/boto3/resources/action.py", line 88, in callresponse = getattr(parent.meta.client, operation_name)(*args, **params)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/client.py", line 415, in _api_callreturn self._make_api_call(operation_name, kwargs)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/client.py", line 731, in _make_api_callhttp, parsed_response = self._make_request(


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/client.py", line 751, in _make_requestreturn self._endpoint.make_request(operation_model, request_dict)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/endpoint.py", line 107, in make_requestreturn self._send_request(request_dict, operation_model)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/endpoint.py", line 180, in _send_requestrequest = self.create_request(request_dict, operation_model)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/endpoint.py", line 120, in create_requestself._event_emitter.emit(event_name, request=request,


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/hooks.py", line 358, in emitreturn self._emitter.emit(aliased_event_name, **kwargs)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/hooks.py", line 229, in emitreturn self._emit(event_name, kwargs)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/hooks.py", line 212, in _emitresponse = handler(**kwargs)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/signers.py", line 95, in handlerreturn self.sign(operation_name, request)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/signers.py", line 167, in signauth.add_auth(request)


File "/home/testcode/.local/lib/python3.8/site-packages/botocore/auth.py", line 401, in add_authraise NoCredentialsError()botocore.exceptions.NoCredentialsError: Unable to locate credentials

最佳答案

你的 ubuntu 机器上有你的 aws 凭证吗?它应该在 ~/.aws/credentials 上寻找它们。

关于ubuntu - 如何使用 Boto3 修复 DynamoDB 的 "NoCredentialsError",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71944302/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com