【发布时间】:2022-01-16 21:32:47
【问题描述】:
我有一个使用 Twilio CLI 运行的 Twilio 应用程序,如下所示:
> twilio phone-numbers:update NUMBER --sms-url=http://localhost:5000
以上运行成功。
然后我在一个单独的终端中运行了这段代码:
from flask import Flask, request, redirect
from twilio.twiml.messaging_response import MessagingResponse
app = Flask(__name__)
@app.route("/", methods=['GET', 'POST'])
def sms_reply():
"""Respond to incoming calls with a simple text message."""
# Start our TwiML response
resp = MessagingResponse()
# Add a message
resp.message("The Robots are coming! Head for the hills!")
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
我以前可以在执行这两个操作后通过 SMS 发送和接收响应,但现在我不能。向它发送短信后,我没有收到任何回复。当我打开浏览器到生成的 ngrok 链接时,我得到:
但是好像没有转发到我的号码...
我也曾在不使用 Twilio-CLI 的情况下使用 ngrok 进行尝试,同样的事情发生了......
为什么会这样?
更多信息:
-
我使用的是免费试用版,我发送消息的电话号码是经过验证的来电显示。
-
我 pip 安装了 pyngrok 并卸载了它,我不确定这是否对它有任何影响,因为我在使用它的过程中意识到了这个问题。删除并重新启动后问题仍然存在。
-
运行上面的代码,输出如下:
* Serving Flask app "test" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 111-796-191
- 刷新页面得到以下结果:
Failed to complete tunnel connection
The connection to https://5774-121-7-155-247.ngrok.io was successfully tunneled to your ngrok client, but the client failed to establish a connection to the local address localhost:5000.
Make sure that a web service is running on localhost:5000 and that it is a valid address.
The error encountered was: dial tcp [::1]:5000: connect: connection refused
任何帮助将不胜感激
【问题讨论】: