2014-01-12 50 views
0

從Heroku本地運行它時,它運行良好。在日誌中,我收到的錯誤是超時錯誤。Flask應用程序無法在Heroku上運行

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) 

我procfile這樣說:

web: python routes.py 

這裏有一些新的錯誤日誌:

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 

它看起來像這些新的日誌都指向東西的Heroku相關。顯然,我不確定。

+0

Heroku日誌特別說明了什麼? – dirn

+0

@dirn在 – metersk

+0

以上添加日誌@Barnaby:請在問題本身的文本中包含您遇到問題的代碼以及相關的日誌記錄結果。發佈指向整個源代碼庫和日誌的鏈接並不理想,因爲這些鏈接可能會中斷/更改,從而使您的問題對可能出現同樣問題的未來用戶無用。此外,它使人們不太可能想要解決問題,因爲他們必須做額外的工作來調試您的_entire_應用程序/設置,而不是首先明確指出問題所在。 –

回答

3

由於日誌狀態:

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

你是不是結合所提供的PORT變量等Heroku的終止程序。如果你只是想玩玩的Heroku +瓶那麼簡單你__main__行更改爲:

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

如果需要處理,你可能會希望看到瓶的文檔的部分上deploying into standard WSGI containers兩個以上的併發連接。

+0

太好了,謝謝! – metersk

+0

我在heroku日誌'2014-01-14T02:36:12.390760 + 00:00 app [web.1]中得到這個錯誤:ImportError:無法導入名稱environ'我完全按照上面的代碼添加了代碼,在我的文件頂部添加了導入語句,其中的其他導入是? – metersk

+0

@Barnaby - nope,它應該是從'os import environ'而不是'from sys' - 這在這個例子中已經被修復了。 –

相關問題