python - Twilio 上的失败消息
问题描述
我使用flask和Twilio构建了一个whatapp聊天机器人,但是当我检查我的控制台时似乎收到了失败的消息。状态显示为失败,出现未知错误。当我检查我的调试器时,我看到了错误消息
HTTP retrieval failure
在对我的烧瓶应用程序进行一些更改后,我开始收到这些错误。我尝试撤消所有更改,但现在不是作为状态接收,而是状态现在显示为失败。我尝试重新启动我的 ngrok 并更改我的 Twilio 上的 url,但这也没有改变任何东西。
这是我的代码:
from flask import Flask, request
import requests
from twilio.twiml.messaging_response import MessagingResponse
import random
app = Flask(__name__)
@app.route('/bot', methods=['POST'])
def bot():
incoming_msg = request.values.get('Body', '').lower()
resp = MessagingResponse()
msg = resp.message()
responded = False
if incoming_msg == 'help':
#return options available
output = 'This is a chatbot designed to send statistics, linear algebra and general programming problem questions. Please type in either "Python", "Statistics" or Linear Algebra" to get a random problem.'
msg.body(output)
responded = True
if 'python' in incoming_msg:
with open("C://Users//User//Downloads//python_test.txt", "r") as f:
lines = f.readlines()
code = random.choice(lines)
msg.body(code)
responded = True
if 'quote' in incoming_msg:
# return a quote
r = requests.get('https://api.quotable.io/random')
if r.status_code == 200:
data = r.json()
quote = f'{data["content"]} ({data["author"]})'
else:
quote = 'I could not retrieve a quote at this time, sorry.'
msg.body(quote)
responded = True
if 'thegradientboost' in incoming_msg:
message = 'Test \
'. Additional text' \
'More text,' \
'end of text.' \
'a bit more text' \
'conclusion.'
msg.body(message)
responded = True
if not responded:
msg.body('Word not included.')
return str(resp)
if __name__ == '__main__':
app.run(debug=True)
解决方案
推荐阅读
- function - kotlin中的覆盖方法和通用方法有什么区别?
- java - 运行flutter run时出错:无法合并dex
- java - SequentialTransition 重复超过 cylcecount
- laravel - 尽管上传了新的(Cpanel),但浏览器仍在基于旧的 php 源代码呈现页面
- mysql - 计算数据透视表内的标准差
- reactjs - React:如何将 refs 转发给多个孩子?
- c# - 从列表中删除字段等于某些项目字段的项目
- web - 通过 websocket 将 kubernetes 日志暴露给浏览器
- spring-boot - CrudRepository 测试用例,无需在数据库中插入数据
- json - 如何使用 alamofire swift 解析这个 json