Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » UnboundLocalError: local variable 'resolver' referenced before assignment [RSS Feed]

#1 June 11, 2010 00:30:08

Marcus W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

UnboundLocalError: local variable 'resolver' referenced before assignment


mod_wsgi (pid=2639): Exception occurred processing WSGI script '/home/
webapps/apache/tinygraph.wsgi'.
Traceback (most recent call last):
File "/home/webapps/.virtualenvs/tinygraph/lib/python2.6/site-
packages/Django-1.2.1-py2.6.egg/django/core/handlers/wsgi.py", line
241, in __call__
response = self.get_response(request)
File "/home/webapps/.virtualenvs/tinygraph/lib/python2.6/site-
packages/Django-1.2.1-py2.6.egg/django/core/handlers/base.py", line
142, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)
UnboundLocalError: local variable 'resolver' referenced before
assignment

I have just set up a brand new Django project called tinygraph and I
am using WSGI and virutalenv in combination.

I have took a peak at the Django source code and resolver is not
assigned a value unless a urlconf is set,
I though this might be because I had defined no url tuples in the
urlpatterns variable, however that did not solve the issue.

I just cannot figure it out, I am sure it will be something really
simple,
Thanks for any help,

Marcus

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 11, 2010 13:57:45

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

UnboundLocalError: local variable 'resolver' referenced before assignment


On 11 juin, 00:45, Marcus Whybrow <marcus.whyb...@gmail.com> wrote:
> mod_wsgi (pid=2639): Exception occurred processing WSGI script '/home/
> webapps/apache/tinygraph.wsgi'.
> Traceback (most recent call last):
>   File "/home/webapps/.virtualenvs/tinygraph/lib/python2.6/site-
> packages/Django-1.2.1-py2.6.egg/django/core/handlers/wsgi.py", line
> 241, in __call__
>     response = self.get_response(request)
>   File "/home/webapps/.virtualenvs/tinygraph/lib/python2.6/site-
> packages/Django-1.2.1-py2.6.egg/django/core/handlers/base.py", line
> 142, in get_response
>     return self.handle_uncaught_exception(request, resolver, exc_info)
> UnboundLocalError: local variable 'resolver' referenced before
> assignment
>
> I have just set up a brand new Django project called tinygraph and I
> am using WSGI and virutalenv in combination.
>
> I have took a peak at the Django source code and resolver is not
> assigned a value unless a urlconf is set,
> I though this might be because I had defined no url tuples in the
> urlpatterns variable, however that did not solve the issue.

NB : r12953 here but since line 142 seems to match your traceback I
guess this file didn't changed.

Had a look too. 'resolver' is first assigned at line 76, so the real
exception must happen in lines 74:76:

urlconf = settings.ROOT_URLCONF
urlresolvers.set_urlconf(urlconf)
resolver = urlresolvers.RegexURLResolver(r'^/',
urlconf)

You could get more info step-debugging these lines. Anyway - the fact
that you get an UnboundLocalError at line 142 shadowing the real
exception is an obvious bug - it ShouldntHappen(tm) -, so I strongly
suggest you fill a bug report (nb : just checked on the trunk, a
couple things changed but AFAICT the problem is still here).



> I just cannot figure it out, I am sure it will be something really
> simple,
> Thanks for any help,

In the meantime, you can try patching django/core/handlers/base.py to
get the real exception, solve it and revert. Replace line 142 with a
plain "raise" instruction so you short-circuit any other code and
rerun your code. You should get a more useful error message.

FWIW, what happens when using the dev server ?


HTH

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 June 11, 2010 14:26:39

Marcus W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

UnboundLocalError: local variable 'resolver' referenced before assignment


I have found a ticket already open for this problem (http://
code.djangoproject.com/ticket/13684),
The problem was in fact that I had a settings.py file and a module
called settings with default and local settings residing inside it.
There must have been some confusion and moving the settings.py file
into the module resolved the name conflict and allowed Django to run
correctly.

On Jun 11, 1:57 pm, bruno desthuilliers
<bruno.desthuilli...@gmail.com> wrote:
> On 11 juin, 00:45, Marcus Whybrow <marcus.whyb...@gmail.com> wrote:
>
>
>
>
>
> > mod_wsgi (pid=2639): Exception occurred processing WSGI script '/home/
> > webapps/apache/tinygraph.wsgi'.
> > Traceback (most recent call last):
> >   File "/home/webapps/.virtualenvs/tinygraph/lib/python2.6/site-
> > packages/Django-1.2.1-py2.6.egg/django/core/handlers/wsgi.py", line
> > 241, in __call__
> >     response = self.get_response(request)
> >   File "/home/webapps/.virtualenvs/tinygraph/lib/python2.6/site-
> > packages/Django-1.2.1-py2.6.egg/django/core/handlers/base.py", line
> > 142, in get_response
> >     return self.handle_uncaught_exception(request, resolver, exc_info)
> > UnboundLocalError: local variable 'resolver' referenced before
> > assignment
>
> > I have just set up a brand new Django project called tinygraph and I
> > am using WSGI and virutalenv in combination.
>
> > I have took a peak at the Django source code and resolver is not
> > assigned a value unless a urlconf is set,
> > I though this might be because I had defined no url tuples in the
> > urlpatterns variable, however that did not solve the issue.
>
> NB : r12953 here but since line 142 seems to match your traceback I
> guess this file didn't changed.
>
> Had a look too. 'resolver' is first assigned at line 76, so the real
> exception must happen in lines 74:76:
>
>                 urlconf = settings.ROOT_URLCONF
>                 urlresolvers.set_urlconf(urlconf)
>                 resolver = urlresolvers.RegexURLResolver(r'^/',
> urlconf)
>
> You could get more info step-debugging these lines. Anyway - the fact
> that you get an UnboundLocalError at line 142 shadowing the real
> exception is an obvious bug - it ShouldntHappen(tm) -, so I strongly
> suggest you fill a bug report (nb : just checked on the trunk, a
> couple things changed but AFAICT the problem is still here).
>
> > I just cannot figure it out, I am sure it will be something really
> > simple,
> > Thanks for any help,
>
> In the meantime, you can try patching django/core/handlers/base.py to
> get the real exception, solve it and revert. Replace line 142 with a
> plain "raise" instruction so you short-circuit any other code and
> rerun your code. You should get a more useful error message.
>
> FWIW, what happens when using the dev server ?
>
> HTH

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 June 11, 2010 15:33:03

bruno d.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

UnboundLocalError: local variable 'resolver' referenced before assignment


On 11 juin, 15:26, Marcus Whybrow <marcus.whyb...@gmail.com> wrote:
> I have found a ticket already open for this problem (http://
> code.djangoproject.com/ticket/13684),
> The problem was in fact that I had a settings.py file and a module
> called settings with default and local settings residing inside it.

If you mean "a directory with an __init__.py and some other .py
files", this is named a "package" in Python. A Python "module" is a
single .py file.

And indeed, having two modules or package or a module and a package by
the same name in your import path is a sure way to get unpredictable
results !-)

> There must have been some confusion and moving the settings.py file
> into the module resolved the name conflict and allowed Django to run
> correctly.

Hmmm. Not sure this is enough to cleanly solve your problem - might
seems to work but possibly not with the desired settings values. I
strongly suggest your read the relevant chapter in Python's FineManual
and experiment a bit with modules and packages to get a good enough
grasp of how all this works:http://docs.python.org/tutorial/modules.htmlHTH
B.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » UnboundLocalError: local variable 'resolver' referenced before assignment [RSS Feed]

Board footer

Moderator control

Enjoy the 15th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support