0

It runs fine when I run it locally from Heroku. In the logs, the error I'm getting is a timeout error.

from flask import Flask, render_template, request
import requests
import json

app = Flask(__name__)

def decrementList(words):
    for w in [words] + [words[:-x] for x in range(1,len(words))]:
        url = 'http://ws.spotify.com/search/1/track.json?q='
        request = requests.get(url + "%20".join(w))

        json_dict = json.loads(request.content)
        track_title = ' '.join(w)

        for track in json_dict["tracks"]:
            if track["name"].lower() == track_title.lower() and track['href']:
                return "http://open.spotify.com/track/" + track["href"][14:], words[len(w):], track["href"][14:]

    return "Sorry, no (more) track matches found!", None, ""  

@app.route('/')
def home():
    message = request.args.get('q', '').split()
    first_arg = ' '.join(message)
    playlist = []
    results = []
    while message:
        href, new_list, for_playlist = decrementList(message)
        message = new_list
        results.append(href)

        playlist.append(for_playlist)

    playlist_link = ','.join(playlist)


    return render_template('home.html', first_arg=first_arg, results=results, playlist_link=playlist_link)

if __name__ == '__main__':
    app.run(debug=False)

My procfile says this:

web: python routes.py

Here are some new Error Logs:

2014-01-14T02:47:38.042655+00:00 heroku[web.1]: Process exited with status 137
2014-01-14T02:47:41.346999+00:00 heroku[web.1]: Starting process with command `python routes.py`
2014-01-14T02:47:42.443673+00:00 app[web.1]: Traceback (most recent call last):
2014-01-14T02:47:42.443673+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/logging/__init__.py", line 851, in emit
2014-01-14T02:47:42.443673+00:00 app[web.1]:     msg = self.format(record)
2014-01-14T02:47:42.443673+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/logging/__init__.py", line 724, in format
2014-01-14T02:47:42.443673+00:00 app[web.1]:     return fmt.format(record)
2014-01-14T02:47:42.443673+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/logging/__init__.py", line 464, in format
2014-01-14T02:47:42.443673+00:00 app[web.1]:     record.message = record.getMessage()
2014-01-14T02:47:42.443673+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/logging/__init__.py", line 328, in getMessage
2014-01-14T02:47:42.443673+00:00 app[web.1]:     msg = msg % self.args
2014-01-14T02:47:42.443673+00:00 app[web.1]: TypeError: %d format: a number is required, not str
2014-01-14T02:47:42.444029+00:00 app[web.1]: Logged from file _internal.py, line 87

It looks like these new logs are pointing to something heroku related. Obviously, I am not sure though.

metersk
  • 11,803
  • 21
  • 63
  • 100
  • What do the Heroku logs say specifically? – dirn Jan 12 '14 at 21:09
  • @dirn added logs above – metersk Jan 12 '14 at 23:15
  • @Barnaby: Please include the code that you are having problems with and the pertinent logging results _in the text of the question itself_. Posting links to an entire source code repository and log is not considered ideal, since those links could break/change, leaving your question useless for future users who might be having the same problem. Additionally, it makes it less likely that someone wants to solve the problem, since they have to do additional work to debug your _entire_ application/setup, rather than you first specifying precisely what the issue is. – Mark Hildreth Jan 12 '14 at 23:20
  • @MarkHildreth I was going to do that, but the code runs fine locally, and I figured it was an issue with the Procfile. Will add them main .py file now. – metersk Jan 12 '14 at 23:27

1 Answers1

3

As the logs state:

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch

You are not binding to the provided PORT variable and so Heroku terminates your program. If you just want to play around with Heroku + Flask then simply change your __main__ line to:

if __name__ == '__main__':
    from os import environ
    app.run(debug=False, port=environ.get("PORT", 5000), processes=2)

If this needs to handle more than two concurrent connections you will probably want to see the section of Flask's docs on deploying into standard WSGI containers.

Sean Vieira
  • 155,703
  • 32
  • 311
  • 293
  • i am getting this error in the heroku logs `2014-01-14T02:36:12.390760+00:00 app[web.1]: ImportError: cannot import name environ` i added the code exactly as it is above, should i have added the import statement at the top of my file where the other imports are? – metersk Jan 14 '14 at 02:38
  • @Barnaby - nope, it should have been `from os import environ` rather than `from sys` - that's been fixed in the example. – Sean Vieira Jan 14 '14 at 02:43
  • @Barnaby - looks like a Heroku-specific error - worth raising with them. – Sean Vieira Jan 14 '14 at 02:53