无法验证Facebook的webhook订阅中的URL在后端和ssl的python烧瓶 [英] Fail to validate URL in Facebook webhook subscription with python flask on the back end and ssl
问题描述
所以我有名称的服务器(即)www.mysite.com
我得到了该域的有效SSL证书,apache设置正确 - 一切正常。
我的服务器上有一个python代码,它运行烧瓶,我指向这些服务器证书:
从烧瓶导入Flask,从pymessenger.bot导入请求
Bot
导入请求
import ipdb
从OpenSSL导入SSL
app = Flask(__ name__)
TOKEN =< access_token>
bot = Bot(TOKEN)
@ app.route(/ webhook,methods = ['GET','POST'])
def hello():
如果request.method =='GET':
if(request.args.get(hub.verify_token)==my_awesome_token):
return request.args.get( hub.challenge)
如果request.method =='POST':
output = request.json
event = output ['entry'] [0] ['message']
for x in event:
if(x.get('message')and x ['message']。get('text'))
message = x ['message'] [ 'text']
recipient_id = x ['sender'] ['id']
bot.send_text_message(recipient_id,message)
else:
pass
return成功
如果__name__ ==__main__:
#尝试这个 - 不运气
#context = SSL.Context(SSL.SSLv23_METHOD)
#context.use_privatekey_file('/ home / mysite.com.key')
#context.use_certificate_file('/ home / intermediate.crt')
#尝试这个 - 同样的结果
context =('/mysite.com.crt','/ mysite .com.key')
app.run(host ='www.mysite.com',port = 5002,debug = True,ssl_context = context)
它开始没有错误,如果我浏览浏览器 - 我看到它获得连接。
端口5002在我的防火墙上打开。
但是当我去FB并尝试订阅该URL时,它会一直失败,并出现这个错误:
无法验证网址。
回调验证失败,出现以下错误:curl_errno = 60;
curl_error = SSL证书问题:无法获取本地颁发者证书;
HTTP状态码= 200;
HTTP消息=连接建立
我已经阅读了一半的互联网可能的原因,看到很多不同的建议,但我不能做任何这些工作 - 我在95%的时间结束了相同的结果。 5% - 其他一些错误,由于Flask出现了一些疯狂设置,我试过。
可能有什么问题?我正在使用从COMODO得到的证书文件。
也尝试在回调网址使用 / webhook
- 没有运气。相同的错误。
也添加了颁发者证书。科莫多将发行自己的证书。在启动服务器时,您需要包括它。
I'm trying to start using new messenger platform from FB. So i have server with name (i.e.) www.mysite.com I got a valid SSL certificate for that domain and apache is setup correctly - all good.
I have a python code on my server which runs flask and i point it to these certificates I got for the server:
from flask import Flask, request
from pymessenger.bot import Bot
import requests
import ipdb
from OpenSSL import SSL
app = Flask(__name__)
TOKEN = "<access_token>"
bot = Bot(TOKEN)
@app.route("/webhook", methods = ['GET', 'POST'])
def hello():
if request.method == 'GET':
if (request.args.get("hub.verify_token") == "my_awesome_token"):
return request.args.get("hub.challenge")
if request.method == 'POST':
output = request.json
event = output['entry'][0]['messaging']
for x in event:
if (x.get('message') and x['message'].get('text')):
message = x['message']['text']
recipient_id = x['sender']['id']
bot.send_text_message(recipient_id, message)
else:
pass
return "success"
if __name__ == "__main__":
# tried this - no luck
#context = SSL.Context(SSL.SSLv23_METHOD)
#context.use_privatekey_file('/home/mysite.com.key')
#context.use_certificate_file('/home/intermediate.crt')
# tried this - also same result
context = ('/mysite.com.crt', '/mysite.com.key')
app.run(host='www.mysite.com',port=5002, debug=True, ssl_context=context)
It starts without error and if I navigate with my browser - i see it gets connections.
port 5002 is open inf my firewall.
But when I go to FB and try to subscribe to that URL - it keeps failing with this error:
The URL couldn't be validated.
Callback verification failed with the following errors: curl_errno = 60;
curl_error = SSL certificate problem: unable to get local issuer certificate;
HTTP Status Code = 200;
HTTP Message = Connection established
I've read half the internet on the possible reasons and saw many different suggestions, but I can't make any of those work - i end up with the same result 95% of the time. 5% - some other error due to Flask bugging out with some "crazy" settings I try.
What can be wrong? I'm using certificate files which I got from COMODO.
Also tried in the call back url to use /webhook
- no luck either. same error.
Add the issuer certificate also. Comodo will issue their own certificate. YOu need to include that while starting the server.
这篇关于无法验证Facebook的webhook订阅中的URL在后端和ssl的python烧瓶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!