我目前正在使用 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 以獲取更多詳細資訊:
檔案“/home/testcode/.local/lib/python3.8/site-packages/flask/app.py”,第 2095 行,呼叫 return self.wsgi_app(environ, start_response)
wsgi_app response = self.handle_exception(e) 中的檔案“/home/testcode/.local/lib/python3.8/site-packages/flask/app.py”,第 2080 行
wsgi_app response = self.full_dispatch_request() 中的檔案“/home/testcode/.local/lib/python3.8/site-packages/flask/app.py”,第 2077 行
檔案“/home/testcode/.local/lib/python3.8/site-packages/flask/app.py”,第 1525 行,在 full_dispatch_request rv = self.handle_user_exception(e)
檔案“/home/testcode/.local/lib/python3.8/site-packages/flask/app.py”,第 1523 行,在 full_dispatch_request rv = self.dispatch_request()
檔案“/home/testcode/.local/lib/python3.8/site-packages/flask/app.py”,第 1509 行,在 dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req .view_args)
檔案“/mnt/c/Users/Test/Desktop/Coding/TestCode/mainapp/webapp.py”,第 139 行,在登錄會話 ["farm"] = DynamoDB.selectItem("Users", session["email"] )
檔案“/mnt/c/Users/Test/Desktop/Coding/TestCode/mainapp/DataBase/DynamoDB.py”,第 147 行,在 selectItem response = table.get_item(
檔案“/home/testcode/.local/lib/python3.8/site-packages/boto3/resources/factory.py”,第 580 行,在 do_action response = action(self, *args, **kwargs)
檔案“/home/testcode/.local/lib/python3.8/site-packages/boto3/resources/action.py”,第 88 行,呼叫 response = getattr(parent.meta.client, operation_name)(*args, **引數)
_api_call 中的檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/client.py”,第 415 行 return self._make_api_call(operation_name, kwargs)
檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/client.py”,第 731 行,在 _make_api_call http,parsed_response = self._make_request(
_make_request 中的檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/client.py”,第 751 行 return self._endpoint.make_request(operation_model, request_dict)
檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/endpoint.py”,第 107 行,在 make_request return self._send_request(request_dict, operation_model)
_send_request request = self.create_request(request_dict, operation_model) 中的檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/endpoint.py”,第 180 行
檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/endpoint.py”,第 120 行,在 create_request self._event_emitter.emit(event_name, request=request,
檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/hooks.py”,第 358 行,在發出回傳 self._emitter.emit(aliased_event_name, **kwargs)
檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/hooks.py”,第 229 行,在發出回傳 self._emit(event_name, kwargs)
_emit response = handler(**kwargs) 中的檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/hooks.py”,第 212 行
處理程式中的檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/signers.py”,第 95 行,回傳 self.sign(operation_name, request)
檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/signers.py”,第 167 行,簽名 auth.add_auth(request)
檔案“/home/testcode/.local/lib/python3.8/site-packages/botocore/auth.py”,第 401 行,在 add_auth 中引發 NoCredentialsError() botocore.exceptions.NoCredentialsError:無法找到憑據
uj5u.com熱心網友回復:
你的 ubuntu 機器上有你的 aws 憑證嗎?它應該在~/.aws/credentials
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/459276.html
