簡體   English   中英

Twilio Flask 錯誤 - 不響應短信

[英]Twilio Flask Error - Does not respond to SMSs

我有一個使用 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 並卸載了它,我不確定這是否對它有任何影響,因為我在使用它的過程中意識到了這個問題。 刪除並重新啟動后問題仍然存在。

  • 運行上面的代碼,這是 output:

 * 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

任何幫助將非常感激

最新的 mac os 使用 flask 的默認端口存在問題。 要解決它,請轉到系統偏好設置 > 共享並取消選擇 AirPlay 接收器。 或者使用flask run --port=5002並重新啟動您的 ngrok 服務器: ngrok http 5002

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM