在MacOS上运行Python Flask时如何解决此错误

2024-09-30 20:38:53 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我在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 "/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'

Tags: inpyappflaskresponserequestlibpackages
1条回答
网友
1楼 · 发布于 2024-09-30 20:38:53

该行:

result = json.loads(results[process_key])

正在从字符串创建dict并查找键process_key

该键不在dict中,因此引发KeyError

查看第159行的代码,了解如何避免该问题

相关问题 更多 >