2016-04-09 18 views
0

作成済みtwitterアプリケーションgoogleアプリケーションエンジンこのアプリケーションを実行中にこのリポジトリhttps://github.com/cybermithun/twitter-search-reply-botを使用すると、このエラーが発生します。誰もがいただきましたコードGoogle App EngineでPythonアプリケーションエラーが発生しました

Internal Server Error 

The server has either erred or is incapable of performing the requested operation. 

Traceback (most recent call last): 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1535, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1529, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 1102, in __call__ 
    return handler.dispatch() 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 572, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/webapp2-2.5.2/webapp2.py", line 570, in dispatch 
    return method(*args, **kwargs) 
    File "/base/data/home/apps/s~leoapp109/1.391952730855998659/main.py", line 32, in get 
    lastTweet = db.GqlQuery("SELECT * FROM LastTweet").fetch(1)[0] 
IndexError: list index out of range 

これで間違って私に言うことができる

#!/usr/bin/env python 
#**strong text** 
# Copyright 2007 Google Inc. 

import datetime 
from google.appengine.ext import db 
import webapp2 
import time 
import sys 
import random 
from twython import Twython, TwythonError 
from google.appengine.ext import db 

class LastTweet(db.Model): 
    tweetId = db.StringProperty() 

class MainHandler(webapp2.RequestHandler): 
    def get(self): 
     idnum = 0 
     lastTweet = db.GqlQuery("SELECT * FROM LastTweet").fetch(1)[0] 

#  try: 
#   lastTweet = LastTweet.all() 
#  except: 
#   lastTweet = None 
#  if lastTweet != None: 
#   idnum = lastTweet.tweetId 
#  else: 
#   idnum = "0" 


     apiKey = 'QQQ' 
     apiSecret = 'QQQ' 
     accessToken = 'QQQ' 
     accessTokenSecret = 'QQQ' 
     twitter = Twython(apiKey,apiSecret,accessToken,accessTokenSecret) 
     message = "Hi, if you Love Wine you will Love to Wear this Wine T-Shirt www.teespring.com/WineT" 
     search_results = twitter.search(q="#Winelover", since_id = idnum, count=20) 
     print(search_results) 
     for tweet in search_results["statuses"]: 
      screenname = "@" + tweet["user"]["screen_name"]+" "; 
      print tweet["id_str"] 
      try: 
       #self.response.write('Hello world!') 
       twitter.update_status(status=screenname + message, in_reply_to_status_id=tweet["id_str"]) 
      except TwythonError: 
       pass 
      idnum = tweet["id_str"] 
      print(idnum) 
     if search_results: 
      lastTweet.tweetId = idnum 
      lastTweet.put() 

     # self.response.write('Hello world!') 

app = webapp2.WSGIApplication([ 
    ('/', MainHandler) 
], debug=True) 
+0

トレースバックをフォーマットできますか?あなたの投稿を編集し、トレースバックを選択し、コードブレースをクリックします。 – snakecharmerb

+0

フェッチが空のコンテナを返すように見えます。 – cdarke

答えて

1

私のコードでトレースバックの最後の行は、問題原因となったコードの行を識別します

lastTweet = db.GqlQuery("SELECT * FROM LastTweet").fetch(1)[0] 

をし、問題の内容を教えてください:

IndexError: list index out of range

コードでは、db.GqlQuery("SELECT * FROM LastTweet").fetch(1)の結果がlistであると予想し、そのリストの最初の要素(インデックス0の要素)をlastTweetに割り当てます。しかし、リストは空であるため、インデックス0には要素がないため、IndexErrorが得られます。あなたは

try: 
    lastTweet = db.GqlQuery("SELECT * FROM LastTweet").fetch(1)[0] 
except IndexError: 
    lastTweet = None # or whatever 

やケースのようだとして、あなただけの、単一のつぶやきを取得している場合、呼び出し例外を処理するtry/exceptブロック内のコードをラップするか必要がある。この問題を解決するには

クエリのgetツイートを取得する方法またはなし:

lastTweet = db.GqlQuery("SELECT * FROM LastTweet").get() 
if lastTweet: 
    # do stuff 
+0

ねえ、私の質問に答えてくれてありがとう私はあなたのコードがうまくいかないことを試しました、私は上記の私のコードをチェックすることができますが含まれています。 – Leonardo19

関連する問題