在MacOS上运行Python Flask时如何解决此错误
这是我在macOS上运行python flask应用程序时遇到的错误。我怎样才能解决它在MacOS上运行Python Flask时如何解决此错误,python,python-3.x,flask,Python,Python 3.x,Flask,这是我在macOS上运行python flask应用程序时遇到的错误。我怎样才能解决它 Traceback (most recent call last): File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File
Traceback (most recent call last):
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/flask_cors/extension.py", line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/connexion/decorators/decorator.py", line 48, in wrapper
response = function(request)
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/connexion/decorators/uri_parsing.py", line 144, in wrapper
response = function(request)
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/connexion/decorators/validation.py", line 184, in wrapper
response = function(request)
File "/Users/truongnguyen/Library/Python/3.6/lib/python/site-packages/connexion/decorators/parameter.py", line 121, in wrapper
return function(**kwargs)
File "/Users/truongnguyen/vRoute_Algo/server/server.py", line 159, in algo_handler
result = json.loads(results[process_key])
File "<string>", line 2, in __getitem__
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/managers.py", line 772, in _callmethod
raise convert_to_error(kind, result)
KeyError: '5c04fa020bfc60873bc7d34b-5c04fa020bfc60873bc7d34b'
回溯(最近一次呼叫最后一次):
wsgi_应用程序中的文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site packages/flask/app.py”,第2447行
response=self.full\u dispatch\u request()
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site-packages/flask/app.py”,第1952行,完整发送请求
rv=自身处理用户异常(e)
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site-packages/flask_-cors/extension.py”,第165行,在wrapped_函数中
请求后返回cors(应用程序作出响应(f(*args,**kwargs)))
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site packages/flask/app.py”,第1821行,在handle\u user\u exception中
重放(exc_类型、exc_值、tb)
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site-packages/flask/_-compat.py”,第39行,在reraise中
增值
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site-packages/flask/app.py”,第1950行,完整发送请求
rv=自我分派请求()
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site packages/flask/app.py”,第1936行,在分派请求中
返回self.view_函数[rule.endpoint](**req.view_参数)
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site packages/connexion/decorators/decorator.py”,第48行,在包装器中
响应=功能(请求)
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site packages/connexion/decorators/uri_parsing.py”,第144行,在包装器中
响应=功能(请求)
包装器中的文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site packages/connexion/decorators/validation.py”,第184行
响应=功能(请求)
文件“/Users/trunnguyen/Library/Python/3.6/lib/Python/site-packages/connexion/decorators/parameter.py”,第121行,在包装器中
返回函数(**kwargs)
文件“/Users/trunnguyen/vRoute_Algo/server/server.py”,第159行,在Algo_处理器中
result=json.load(结果[process\u key])
文件“”,第2行,在\uu getitem中__
文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/managers.py”,第772行,在调用方法中
引发转换为错误(种类、结果)
键错误:“5c04fa020bfc60873bc7d34b-5c04fa020bfc60873bc7d34b”
行:
result = json.loads(results[process_key])
正在从字符串创建dict,并查找键进程\键
该键不在dict中,因此引发KeyError
查看
server.py
第159行的代码,看看如何避免这个问题。使用pipenv
或python诗歌
可以避免这个问题。请务必发布一个“最简单的完整可验证示例”来说明您的代码,而不是期望人们猜测您正在运行的代码。。。