【问题标题】:Method not allowed - 405 Error - with Twilio API, using flask and python, heroku方法不允许 - 405 错误 - 使用 Twilio API,使用烧瓶和 python,heroku
【发布时间】:2014-01-22 06:20:01
【问题描述】:

我正在关注有关通过 API 发送 SMS 的 Twilio 教程。我遵循了所有步骤,但是,我收到了 405 错误。我的代码:

from flask import Flask
from twilio import twiml
import os

app = Flask(__name__)

@app.route('/sms', methods=['POST'])
def sms():
    r = twiml.Response()
    r.sms("This is awesome!")
    return str(r)

if __name__ == '__main__':
    port = int(os.environ.get('PORT', 5000))

    if port == 5000:
        app.debug = True

    app.run(host='0.0.0.0', port=port)

我在调用我的 url 时收到 405 错误(方法不允许),它看起来像:http://my-url.herokuapp.com/sms,它也像这样与 twilio 帐户相关联。当我包含“GET”时,一切正常,但这不是根据教程。有什么提示吗?

【问题讨论】:

  • 该 URL 只有在你 POST 的情况下才有效,如果你只是在浏览器中访问它,你会得到 405 因为 URL 仅映射为 POST .真正的问题是什么?

标签: python heroku flask twilio http-status-code-405


【解决方案1】:

查看the repository,您似乎实际上需要向 Twillo 为您代理的号码发送短信。如果您还想在浏览器中访问 URL,则需要将 'GET' 添加到 methods 列表(如您所见)。

【讨论】:

    猜你喜欢
    • 2014-03-08
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    • 1970-01-01
    • 2021-04-27
    • 2014-07-28
    • 2020-07-21
    • 1970-01-01
    相关资源
    最近更新 更多