0

在运行代码时

    data = urllib.urlencode(parameters)
        req = urllib2.Request(url, data)
                 logging.info('shivaniHAHOHJSJKDNVJNCMBVJDCVHJSHHHHEKLLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO')
        logging.info(data)
        try:
            response = urllib2.urlopen(req)
        except urllib2.URLError, e:
            self.redirect('/error')
        json_post = response.read()
        data = json.loads(json_post)
        self.redirect('/'+str(data))
        response_dict = simplejson.loads(json_post)

        virustotal = VirusTotal()
        logging.info('1111111111111111111111111111111111111111111111111')
        logging.info('result')
        logging.info(data[int('result')])
        if data ['result'] == 0:
            virustotal_result = True

我在我的日志文件中得到关注

   ValueError: invalid literal for int() with base 10: 'result'
   INFO     2013-05-07 12:14:19,142 server.py:561] default: "GET /query?     url=abc.com&submit=Scan HTTP/1.1" 500 -
   INFO     2013-05-07 12:16:01,857 server.py:561] default: "GET / HTTP/1.1" 200 1236
   INFO     2013-05-07 12:16:01,894 server.py:561] default: "GET /images/logo.png HTTP/1.1" 304 -
   INFO     2013-05-07 12:16:01,898 server.py:561] default: "GET /css/cssscript.css HTTP/1.1" 304 -
   INFO     2013-05-07 12:16:01,943 server.py:561] default: "GET /images/left.png HTTP/1.1" 304 -
   INFO     2013-05-07 12:16:01,950 server.py:561] default: "GET /images/right.png HTTP/1.1" 304 -
   INFO     2013-05-07 12:16:01,950 server.py:561] default: "GET /images/bg.png HTTP/1.1" 304 -
   INFO     2013-05-07 12:16:02,065 server.py:561] default: "GET /favicon.ico HTTP/1.1" 404 154
   WARNING  2013-05-07 12:16:10,082 urlfetch_stub.py:453] Stripped prohibited headers from URLFetch request: ['Content-Length', 'Host']
   INFO     2013-05-07 19:16:23,915 main.py:420] shivaniHAHOHJSJKDNVJNCMBVJDCVHJSHHHHEKLLOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
   INFO     2013-05-07 19:16:23,917 main.py:421] resource=http%3A%2F%2Fgoogle.com&scan=1&key=b99eeaddac6ef5cf62746beffd71f1e16708b6db6085de243f050e241c6c671f
   WARNING  2013-05-07 12:16:23,924 urlfetch_stub.py:453] Stripped prohibited headers from URLFetch request: ['Content-Length', 'Host']
   INFO     2013-05-07 19:16:33,023 main.py:432] 1111111111111111111111111111111111111111111111111
   INFO     2013-05-07 19:16:33,026 main.py:433] result
   ERROR    2013-05-07 19:16:33,028 webapp2.py:1528] invalid literal for int() with base 10: 'result'


     Traceback (most recent call last):
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1253, in default_dispatcher
    return route.handler_adapter(request, response)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 1077, in __call__
    return handler.dispatch()
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 547, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.3\webapp2.py", line 545, in dispatch
    return method(*args, **kwargs)
  File "C:\Users\Shivani\Desktop\malbee-phish (1)\main.py", line 434, in get
    logging.info(data[int('result')])
ValueError: invalid literal for int() with base 10: 'result'

可能是什么原因..??如果我在没有 int() 的情况下尝试 data['result'] 它会给我以下错误 TypeError: list indices must be integers, not str

4

2 回答 2

3

好吧,这条线当然行不通

logging.info(data[int('result')]) 应该如何int('result')工作?

您的堆栈跟踪准确地告诉您问题所在。

所以我问你的问题是你在哪里获得价值result

data['result'] 只有在 data 是一个字典并且你有一个值为“result”的键时才能工作

或者,如果 data 是一个列表(这是 TypError 列表索引必须是整数,而不是 str 告诉您的内容,那么作为变量的结果必须在某个时候被分配一个整数值。并且您刚刚提供的代码中没有任何地方是结果(一个变量)曾经赋值过。

于 2013-05-07T06:40:23.333 回答
2

你有int('result')它永远不会工作。也许你的意思是int(result)

(虽然我也看不出它是如何工作的,因为你从来没有分配给一个变量result。)

于 2013-05-07T08:43:21.080 回答