0

I was following a Twilio tutorial on sending SMS through the API. I followed all the steps, however, I am receiving a 405 error. My code:

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)

I am getting a 405 error (method not allowed), when calling my url, which looks like: http://my-url.herokuapp.com/sms, which is also associated like this to the twilio account. When I include 'GET', everything works, this is not according to tutorial however. Any hints?

1
  • 1
    That URL will only work if you POST something to it, if you just access it in the browser as you have done, you'll get 405 because the URL is only mapped for POST. What is the actual problem? Jan 4, 2014 at 20:02

1 Answer 1

2

Looking at the repository it seems that you will actually need to text to the number that Twillo is proxying for you. If you want to access the URL in your browser as well you will need to add 'GET' to the methods list (as you discovered).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.