Я создал чат-бот whatapp, используя flask и Twilio, но, похоже, получаю сообщения об ошибках при проверке консоли. Статус отображается как сбой с неизвестной ошибкой. Когда я проверяю свой отладчик, я вижу сообщение об ошибке
HTTP retrieval failure
Я начал получать эти ошибки после внесения нескольких изменений в мое приложение flask. Я попытался отменить все изменения, но теперь вместо получения статуса в качестве статуса теперь он отображается как сбойный. Я попытался перезапустить свой ngrok и изменить URL-адрес на моем Twilio, но это тоже ничего не изменило.
Вот мой код:
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)