我正在尝试在服务器中运行 python 代码以接收 webhook 请求,这些请求只是 JSON 格式的 POST 请求。但是,当我使用 Flask 设置服务器时,我获得了:
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 404 NOT FOUND
Content-Type: text/html; charset=utf-8
Content-Length: 232
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
代码是这样的:
from flask import Flask, request, abort
from flup.server.fcgi import WSGIServer
app = Flask(__name__)
@app.route('/webhookListener.py')
def webhook():
if request.method == 'POST':
print(request.json)
return 'success', 200
else:
abort(400)
if __name__ == '__name__':
WSGIServer(app(), bindAddress='/path/to/my/server/root').run()