一些用户抱怨他们无法访问OSQA上的身份验证设置页面。他们收到500错误。 See Screenshot但是,只有在他们通过“我忘记密码”或更改密码后才会这样做 查看日志,具体错误是:
UnboundLocalError: local variable name 'name' referenced before assignment
还有其他人经历过这个吗?如果是这样,我该如何解决呢 预先感谢您的帮助。!!
日志中的堆栈跟踪内容如下(抱歉格式不正确):
DIRECTORY/forum/templatetags/extra_tags.py TIME: 2012-12-13 09:23:31,419 MSG:extra_tags.py:render:312 Error in declare tag, when evaluating: questions.children_count('answer')
DIRECTORY/apps/django/lib/python2.6/site-packages/django/core/handlers/base.py TIME: 2012-12-14 12:40:31,086 MSG: base.py:handle_uncaught_exception:209 Internal Server Error: /osqa/account/9/authsettings/
Traceback (most recent call last):
File "DIRECTORY/apps/django/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "DIRECTORY/apps/osqa/forum/views/auth.py", line 348, in auth_settings
'name': name,
UnboundLocalError: local variable 'name' referenced before assignment
DIRECTORY/apps/osqa/forum/views/meta.py TIME: 2012-12-14 12:40:31,093 MSG: meta.py:error_handler:200
error executing request:
PATH: /osqa/account/9/authsettings/
USER: USER (1)
METHOD: GET
POST PARAMETERS:
None
GET PARAMETERS:
None
HTTP HEADERS:
mod_wsgi.listener_port: 8080
HTTP_REFERER: URL/osqa/users/9/USER
mod_wsgi.listener_host:
SERVER_SOFTWARE: Apache
SCRIPT_NAME: /osqa
mod_wsgi.handler_script:
SERVER_SIGNATURE:
REQUEST_METHOD: GET
PATH_INFO: /account/9/authsettings/
SERVER_PROTOCOL: HTTP/1.1
QUERY_STRING:
HTTP_ACCEPT_CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.3
HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11
HTTP_CONNECTION: keep-alive
HTTP_COOKIE: sessionid=REDACTED; csrftoken=REDACTED
SERVER_NAME: SERVERNAME
REMOTE_ADDR: SERVERIP
mod_wsgi.request_handler: wsgi-script
wsgi.url_scheme: http
PATH_TRANSLATED: DIRECTORY/apache2/htdocs/account/9/authsettings/
SERVER_PORT: 8080
wsgi.multiprocess: True
mod_wsgi.input_chunked: 0
SERVER_ADDR: SERVERIP
DOCUMENT_ROOT: DIRECTORY/apache2/htdocs
mod_wsgi.process_group:
SCRIPT_FILENAME: DIRECTORY/apps/osqa/scripts/osqa.wsgi
SERVER_ADMIN: you@example.com
wsgi.input: <mod_wsgi.Input object at 0x46feab0>
HTTP_DNT: 1
HTTP_HOST: SERVER:8080
wsgi.multithread: False
mod_wsgi.callable_object: application
REQUEST_URI: /osqa/account/9/authsettings/
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
wsgi.version: (1, 1)
GATEWAY_INTERFACE: CGI/1.1
wsgi.run_once: False
wsgi.errors: <mod_wsgi.Log object at 0x487c4f0>
REMOTE_PORT: 51455
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.8
mod_wsgi.version: (3, 3)
mod_wsgi.application_group: localhost:8080|/osqa
mod_wsgi.script_reloading: 1
wsgi.file_wrapper: <built-in method file_wrapper of mod_wsgi.Adapter object at 0x47bf0a8>
CSRF_COOKIE: REDACTED
HTTP_ACCEPT_ENCODING: gzip,deflate,sdch
COOKIES:
csrftoken: REDACTED
sessionid: REDACTED
EXCEPTION INFO:
Traceback (most recent call last):
File "DIRECTORY/apps/django/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "DIRECTORY/apps/osqa/forum/views/auth.py", line 348, in auth_settings
'name': name,
UnboundLocalError: local variable 'name' referenced before assignment
答案 0 :(得分:1)
查看osqa
的源代码,这里可以找到您遇到问题的行(行号与您的不同,但这可能是由于版本差异):
347 for k in auth_keys:
348 provider = AUTH_PROVIDERS.get(k.provider, None)
349
350 if provider is not None:
351 name = "%s: %s" % (provider.context.human_name, provider.context.readable_key(k))
352 else:
353 from forum.authentication.base import ConsumerTemplateContext
354 "unknown: %s" % ConsumerTemplateContext.readable_key(k)
355
356 auth_keys_list.append({
357 'name': name,
358 'id': k.id
359 })
在第354行看来,我们应该有name = "unknown: %s" % ConsumerTemplateContext.readable_key(k)
,但有人忘了name =
。
我无法100%确定这一点,因为我在osqa
中并不是很了解,但是如果我们保持原样,这句话就不会做任何事情。此外,如果您可以确定k.provider
中AUTH_PROVIDERS
不在provider
的原因,那么您的错误是100%可重现的,我猜这必须漂亮不常见。
您可能想要file a bug at osqa
's bug tracker。要在短期内解决您的问题,您可以:
None
为auth_key
的原因。 (显然,由于当前user
存在AUTH_PROVIDERS
而导致的问题与{{1}}中任何一个不对应。