我制作了一个烧瓶应用程序,它使用 Twilio Webhooks 检测在 whatsapp 上收到的消息。收到消息后,应用程序会向同一电话号码发回一条消息。这可以完美地使用 Flask 和 Ngrok 来部署服务器并公开它。但是,一旦我将它部署到 PythonAnywhere,我就会在 Twilio 控制台中收到 11200 错误。这是代码。
from flask import Flask, request
import requests
from twilio.rest import Client
account_sid = 'xxxxx'
auth_token = 'xxxxx'
client = Client(account_sid, auth_token)
def mmsg(phono, body):
message = client.messages.create(
from_='whatsapp:+14155238886',
body=body,
to=phono,
)
app = Flask(__name__)
@app.route('/post', methods=['POST'])
def bot():
incoming_msg = request.values.get('Body', '').lower()
phono = request.values.get('From', "")
if incoming_msg == 'hi':
mmsg(phono, 'hello!')
if __name__ == '__main__':
app.run()
当我检查 PythonAnywhere 错误日志时,我得到了这个
2020-07-19 13:50:46,569: POST Request: https://api.twilio.com/2010-04-01/Accounts/AC84a8b5837227246efc0c6f9440b6e12c/Messages.json
2020-07-19 13:50:46,570: PAYLOAD: {'To': 'whatsapp:{myphonenumber}', 'From': 'whatsapp:+14155238886', 'Body': 'hello!'}
2020-07-19 13:50:49,576: Exception on /post [POST]
Traceback (most recent call last):
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.twilio.com', port=443): Max retries exceeded with url: /2010-04-01/Accounts/AC84a8b5837227246efc0c6f9440b6e12c/Messages.json (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7fc0504362e8>: Failed to establish a new connection: [Errno 111] Connection refused',))
我试过像message = client.messages.create这样添加另一个键和值。
message = client.messages.create(
from_='whatsapp:+14155238886',
body=item,
to=phono,
AC84a8b5837227246efc0c6f9440b6e12c='83ce0b901ff353f9b9a77222e001d71d'
)
当我尝试这样做时,我在 PythonAnywhere 上遇到了这个错误。
墨色风雨
相关分类