有一个用于接收 POST 的网络服务器,该服务器是一个巨大的管道的一部分,该管道运行 5 分钟以上,具体取决于传入的 POST 因此,FLASK 返回一个 500 代码,我该如何解决这个问题?
代码烧瓶
@app.route("/gitlab-webhook", methods=['POST'])
def githubWebhook():
def load_secret(TOKEN, key):
try:
# slack_message_pipe(step=f'I LOAD JSON')
print(TOKEN, ' !!! ', key)
if TOKEN == key:
return 200
else:
return 404
except Exception as e:
slack_message_pipe(step=e)
try:
content = request.json
data = request.headers
print(type(data))
key = data['X-Gitlab-Token']
load_secret(TOKEN, key)
commits_list = content['commits']
json_dump_for_proj(data=commits_list)
except Exception as e:
slack_message_pipe(step=e)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8889)
错误:
ERROR in app: Exception on /gitlab-webhook [POST]
Traceback (most recent call last):
File "python3.8/site-packages/flask/app.py", line 2070, in wsgi_app
response = self.full_dispatch_request()
File "python3.8/site-packages/flask/app.py", line 1516, in full_dispatch_request
return self.finalize_request(rv)
File "/python3.8/site-packages/flask/app.py", line 1535, in finalize_request
response = self.make_response(rv)
File "/python3.8/site-packages/flask/app.py", line 1698, in make_response
raise TypeError(
TypeError: The view function for 'githubWebhook' did not return a valid response. The function either returned None or ended without a return statement.
"POST /gitlab-webhook HTTP/1.1" 500 -
阅读错误后,想法是使用make_response(),但我还没有从阅读材料中找到有关此主题的示例或任何内容
实现了@insolor 的想法,但决定不聪明