import - Unsure how to resolve this Bottle error (Python) -
here imports:
from bottle import request, route, run, template, static_file, redirect urllib2 import urlopen, urlerror, request pymongo import mongoclient config.development import config import json
and here offending line (and line think may causing issue):
game_id = request.forms.get('game_id') request = request(config['singlegame_url'].replace('$gameid', game_id))
the error i'm getting is:
unboundlocalerror("local variable 'request' referenced before assignment",) traceback (most recent call last): file "/usr/local/lib/python2.7/site-packages/bottle.py", line 862, in _handle return route.call(**args) file "/usr/local/lib/python2.7/site-packages/bottle.py", line 1732, in wrapper rv = callback(*a, **ka) file "app.py", line 23, in add game_id = request.forms.get('game_id') unboundlocalerror: local variable 'request' referenced before assignment
my first thought 2 request
modules causing issues, couldn't error go away messing around imports , importing stuff as
name.
you must rename request
variable else.
python kind of reserves variable name request
local variable due request = ...
before executing code. interpreter executes line game_id = request.forms.get('game_id')
, request
new reserved local variable, is, undefined.
here's example of same issue:
>>> x = 1 >>> def f(): ... print(x) # you'd think prints 1, `x` local variable ... x = 3 >>> f() traceback (most recent call last): file "<pyshell#5>", line 1, in <module> f() file "<pyshell#4>", line 2, in f print(x) unboundlocalerror: local variable 'x' referenced before assignment
Comments
Post a Comment