1

Twilio newbie question:

I created an app that uses the Twilio API as I followed along to the tutorial by General Assembly

The files I added are

  • app.py
  • Procfile
  • requirements.txt

app.py

from flask import Flask
from flask import request
from twilio import twiml
import os

app = Flask(__name__)

@app.route('/caller', methods=['POST'])
def caller():
    response = twiml.Response()
    response.enqueue("Christmas Queue")
    return str(response)


if __name__ == "__main__":
    port = int(os.environ.get('PORT', 5000))
    app.debug = True
    app.run=(host='0.0.0.0'. port=port)


Procfile

web: python app.py


requirements.txt

flask>=0.9
twilio>=3.1

I deployed the app to Heroku. And then I added the URL to Twilio URL for the app

I called to test it, but got an error. Not sure what my next steps can be to troubleshoot this further.

JGallardo
  • 11,074
  • 10
  • 82
  • 96
  • Your Python script has a ton of syntax errors. Is this your actual code? – Blender May 06 '13 at 23:58
  • @Blender I made many mistakes because I was watching the video on a lower resolution screen and I have no previous experience with Python (so I was not aware of the syntax errors). What I have above now reflects what was taught in the class by the person from Twilio. But I appreciate any scripting corrections/suggestions. – JGallardo May 07 '13 at 00:09

2 Answers2

0

Your first task should be to run heroku logs -t and actually look at the Heroku output when your app is deployed.

Femi
  • 64,273
  • 8
  • 118
  • 148
  • Or test the Python script locally before deploying it. – Blender May 07 '13 at 00:04
  • Ok I ran heroku logs -t and got this "2013-05-07T00:10:03.764819+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=POST path=/caller host=desolate-crag-7877.herokuapp.com fwd="107.22.34.255" dyno= connect= service= status=503 bytes=" – JGallardo May 07 '13 at 00:11
  • OK I narrowed this down to Heroku when looking at the logs. Found this on Heroku https://devcenter.heroku.com/articles/error-codes#h14-no-web-processes-running tried the command "heroku ps:scale web=1" but got back "Scaling web dynos... failed ! No such type as web." – JGallardo May 07 '13 at 00:58
  • You should run 2 shells: run `heroku logs -t` in one shell, and then modify/git push in the other. This will let you see exactly what Heroku is having issues with. As @Blender also said: you should make sure the app runs perfectly in your shell before deploying it. Heroku also has the Foreman tool which is installed with the Heroku Toolbelt that will let you test your Procfile and app are working correctly: I'd use those locally and see what happens. – Femi May 07 '13 at 04:09
0

You have a few syntax errors:

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

Remove that equals sign, replace the period with a comma and your script will run.

I would read through Heroku's Python tutorial as well.

Blender
  • 289,723
  • 53
  • 439
  • 496
  • Tried it, but still got an error. Here is the gist https://gist.github.com/JGallardo/5529354 – JGallardo May 07 '13 at 00:16
  • when I called in the voice recording says "an application error has occurred" in the logs I got this "2013-05-07T00:17:45.570589+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=POST path=/caller host=desolate-crag-7877.herokuapp.com fwd="50.16.88.219" dyno= connect= service= status=503 bytes=" – JGallardo May 07 '13 at 00:18
  • @JGallardo: That's Heroku's error message. What's the Python traceback? – Blender May 07 '13 at 00:19
  • was not sure how to answer that question but I found tips for the traceback at http://stackoverflow.com/questions/1508467/how-to-log-my-traceback-error and got "-bash: $log: ambiguous redirect" – JGallardo May 07 '13 at 00:27
  • @JGallardo: Can you scroll through the error logs? There should be a Python traceback in there. Also, can you make sure that your `procfile` is correct? I think there should be a colon after `web`. – Blender May 07 '13 at 00:29