katherine
katherine

Reputation: 1

ValueError: invalid literal for int() with base 10: 'result'

while running the code

    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

i get following in my log file

   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'

what can be the possible reason..?? if i try data['result'] without int() it gives me following error TypeError: list indices must be integers, not str

Upvotes: 0

Views: 2119

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599610

You have int('result') which will never work. Maybe you meant int(result)?

(Although I can't see how that would work either, seeing as you never assign to a variable result.)

Upvotes: 2

Tim Hoffman
Tim Hoffman

Reputation: 12986

Well of course this line won't work

logging.info(data[int('result')]) how is int('result') supposed to work?

Your stack trace is telling you exactly what the problem is.

So the question I ask you where are you getting a value for result

data['result'] could only work if data is a dictionary and you have a key in it with the value "result"

Alternately if data is a list (which is what the TypError list indices must be integers, not str is telling you, then result as a variable must be assigned an integer value at some point. And no where in the code you just presented is result (a variable) ever assigned a value.

Upvotes: 3

Related Questions