[英]How to response with specific json attribute
I'm trying to set up a webhook for slack .我正在尝试为slack设置一个 webhook。 There i need to return "challenge" attribute value to the request below.
我需要将“挑战”属性值返回给下面的请求。 I don't know what to write in "response = make_response((),200)" to response correctly.
我不知道在“response = make_response((),200)”中写什么才能正确响应。
{
"token": "Jhj5dZrVaK7ZwHHjRyZWjbDl",
"challenge": "3eZbrw1aBm2rZgRNFdxV2595E9CY3gmdALWMmHkvFXO7tYXAYM8P",
"type": "url_verification"
}
import os
from flask import Flask
from flask import request
from flask import make_response
app = Flask(__name__)
@app.route('/webhook2')
def hello_slack():
request_json = request.get_json(silent=True, force=True)
response_body = json.dumps(request_json)
response = make_response((),200)
response.headers['Content-Type'] = 'text/plain'
return response
if __name__ == '__main__':
port = int(os.getenv('PORT', 5000))
app.run(debug=False, port=port, host='0.0.0.0')
Hi I see you have a dict just sitting there at the top of the file;嗨,我看到您在文件顶部有一个字典; that seems odd.
这似乎很奇怪。 I would guess you want to have some variable equal that dict and response should use variable[“challenge”]
我猜你想要一些变量等于 dict 和 response 应该使用 variable[“challenge”]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.