2014-03-19 98 views
0

我有一个在我的本地主机服务器上运行得非常好的Python瓶子web服务。现在我已经将它部署在heroku上,并且在我尝试从heroku访问它时显示该应用程序有一些错误,但它不运行。我在本地主机上测试过它(并确认Web服务运行非常好),然后将它部署到heroku上。我正在使用我的Web服务从中检索持久性数据的搁置文件。当它在本地主机上运行它运行良好,但我认为在Heroku它无法检索我的搁置文件的内容。在我以前在Heroku上部署的Web服务中,我曾在每次运行中创建新的搁置文件,但在此Web服务中,我已创建带有持久数据的搁置文件,而我的Web服务只是在不写任何内容的情况下引用此数据到它。在heroku上运行python web服务

这里是我的web服务的脚本:

news_index=shelve.open('IndexedMapping') 

item = [] # list for storing the final results 

with open('TodaysToiScrapedItemsOutput.json') as f: #load json file 
    data = json.load(f) 

input_headline = news_string 
input_headline_list = input_headline.split() 
temp_input_headline_list = [] 

for each_word in input_headline_list: 
    temp_input_headline_list.append(each_word) 


for each_word in temp_input_headline_list: 
    if (each_word.lower() in ignore_this_words): 
     input_headline_list.remove(each_word) 

hit_cnt=0 
key_and_hit_cnt_dict={} 
for each_key in news_index: 
    for each_word in input_headline_list: 
    if(each_word.lower() in each_key): 
     hit_cnt = hit_cnt + 1 
    key_and_hit_cnt_dict[each_key] = hit_cnt 
    hit_cnt=0 

sorted_keys_wrt_hitcnt = sorted(key_and_hit_cnt_dict, key= key_and_hit_cnt_dict.__getitem__,reverse=True) 


i=0 
for each_entry in sorted_keys_wrt_hitcnt: 
    if(i<5): 
     location=news_index[each_entry] 
     item.append({ 'body' : data[location]["body"],'location':location,'key':each_entry,'words':input_headline_list}) 
    i = i+1 

return jsonify({'item':item}) 

编辑

这是我的日志

2014-03-19T10:09:08.000898+00:00 app[web.1]: 2014-03-19 10:09:07 [7] [INFO] Booting worker with pid: 7 
2014-03-19T10:09:08.262376+00:00 heroku[web.1]: State changed from starting to up 
2014-03-19T10:09:18.149027+00:00 heroku[router]: at=info method=GET path=/ host=glacial- plateau-3427.herokuapp.com request_id=203107b5-5c0e-40bd-8e0b-4cdc8649c2f1 fwd="27.251.95.162" dyno=web.1 connect=2ms service=25ms status=404 bytes=384 
2014-03-19T10:09:24.995531+00:00 heroku[router]: at=info method=GET path=/toi/cricket host=glacial-plateau-3427.herokuapp.com request_id=18d612f6-7cf6-4fc0-a686-6a8680cf469f fwd="27.251.95.162" dyno=web.1 connect=2ms service=18ms status=500 bytes=454 
2014-03-19T10:10:45.866027+00:00 heroku[router]: at=info method=GET path=/toi/cricket%20India%20T20 host=glacial-plateau-3427.herokuapp.com request_id=5122179a-dfde-4a22-b916-daa7eec3ec10 fwd="27.251.95.162" dyno=web.1 connect=1ms service=6ms status=500 bytes=454 
2014-03-19T10:13:39.713629+00:00 heroku[router]: at=info method=GET path=/toi/aap%20modi%20kejriwal host=glacial-plateau-3427.herokuapp.com request_id=0426e03c-61bd-4b4f-995b-55a72c91d676 fwd="27.251.95.162" dyno=web.1 connect=1ms service=5ms status=500 bytes=454 
+0

你正在得到什么错误..你能显示你的英雄日志?此外,这个搁置文件是否在git中,或者您是否动态生成它? – anuragal

+0

你知道Heroku dynos有一个完全短暂的filesytem吗? https://devcenter.heroku.com/articles/dynos#isolation-and-security – aychedee

+0

@anuragal Shelve文件是在git中...它已经充满了数据,而不是动态生成.... –

回答

1

聊天

  • 所有讨论过你在代码中访问文件是git的
  • 运行代码

当在我看来,你应该检查你的代码,你是不是从你的代码

  • 获得500错误修改任何文件,它可能会产生一些例外现在是未处理的。你可以做的是将你的代码封装在try-except块中并打印异常。像 -

    try: 
        news_index=shelve.open('IndexedMapping') 
    
        item = [] # list for storing the final results 
    
        with open('TodaysToiScrapedItemsOutput.json') as f: #load json file 
         data = json.load(f) 
    
        input_headline = news_string 
        input_headline_list = input_headline.split() 
        temp_input_headline_list = [] 
    
        for each_word in input_headline_list: 
         temp_input_headline_list.append(each_word) 
    
    
        for each_word in temp_input_headline_list: 
         if (each_word.lower() in ignore_this_words): 
          input_headline_list.remove(each_word) 
    
        hit_cnt=0 
        key_and_hit_cnt_dict={} 
        for each_key in news_index: 
         for each_word in input_headline_list: 
          if(each_word.lower() in each_key): 
           hit_cnt = hit_cnt + 1 
          key_and_hit_cnt_dict[each_key] = hit_cnt 
         hit_cnt=0 
    
        sorted_keys_wrt_hitcnt = sorted(key_and_hit_cnt_dict, key= key_and_hit_cnt_dict.__getitem__,reverse=True) 
    
    
        i=0 
        for each_entry in sorted_keys_wrt_hitcnt: 
         if(i<5): 
          location=news_index[each_entry] 
          item.append({ 'body' : data[location]["body"],'location':location,'key':each_entry,'words':input_headline_list}) 
         i = i+1 
    
        return jsonify({'item':item}) 
    except Exception, e: 
        import traceback 
        traceback.print_exc() 
        return jsonify({'error': str(e)}) 
    
  • +0

    @y。 dixit - 你试过这个吗? – anuragal