shazaman23 / webapp-improved

Automatically exported from code.google.com/p/webapp-improved
Other
0 stars 0 forks source link

i18n exception #51

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. use i18n with latest source tip: 521:3f580c02e6c7
2. start the server and visit the page
3. Exception occurred:

Internal Server Error

The server has either erred or is incapable of performing the requested 
operation.

Traceback (most recent call last):
  File "/home/hua/Public/wsgi/site/module/webapp2.py", line 1536, in __call__
    rv = self.handle_exception(request, response, e)
  File "/home/hua/Public/wsgi/site/module/webapp2.py", line 1530, in __call__
    rv = self.router.dispatch(request, response)
  File "/home/hua/Public/wsgi/site/module/webapp2.py", line 1278, in default_dispatcher
    return route.handler_adapter(request, response)
  File "/home/hua/Public/wsgi/site/module/webapp2.py", line 1102, in __call__
    return handler.dispatch()
  File "/home/hua/Public/wsgi/site/module/webapp2.py", line 572, in dispatch
    return self.handle_exception(e, self.app.debug)
  File "/home/hua/Public/wsgi/site/module/webapp2.py", line 570, in dispatch
    return method(*args, **kwargs)
  File "/home/hua/Public/wsgi/site/main.py", line 19, in get
    i18n.get_i18n().set_locale(locale)
  File "/home/hua/Public/wsgi/site/module/webapp2_extras/i18n.py", line 894, in get_i18n
    request = request or webapp2.get_request()
  File "/home/hua/Public/wsgi/site/module/webapp2.py", line 1720, in get_request
    assert getattr(_local, 'request', None) is not None, _get_request_error
AssertionError: Request global variable is not set.

What is the expected output? What do you see instead?
Hello Webapp2!

If I disable i18n (not using it) then everything is fine.

What version of the product are you using? On what operating system?
521:3f580c02e6c7
On Ubuntu 11.10, nginx + uwsgi

Please provide any additional information below.
Source code:

 1 import sys
  2 sys.path.append('/home/hua/Public/wsgi/site')
  3 sys.path.append('/home/hua/Public/wsgi/site/module')
  4 sys.path.append('/home/hua/Public/wsgi/site/trac/cgi-bin')
  5 from module import webapp2
  6 from trac_wsgi import application as trac_app
  7 from module.webapp2_extras import i18n
  8 from module.webapp2_extras.i18n import gettext as _
  9 
 10 
 11 config = {}
 12 config['webapp2_extras.i18n'] = {
 13         'translations_path': 'locale',
 14 }
 15 
 16 class HelloWebapp2(webapp2.RequestHandler):
 17         def get(self, s):
 18                 locale = self.request.GET.get('locale', 'en_US')
 19                 i18n.get_i18n().set_locale(locale)
 20                 message = _("Hello Webapp2!")
 21                 self.response.write(message)
 22 
 23 app = webapp2.WSGIApplication([ ('/(.*)', HelloWebapp2), ], debug=True, config=config)
 24 def application(env, start_response):
 25         tmp = ''
 26         for i in env.keys():
 27                 tmp = tmp + '\n' + i + ' : ' + str(env[i])
 28         if env['PATH_INFO'].startswith('/py/trac'):
 29                 env['SCRIPT_NAME'] = '/py/trac'
 30                 env['PATH_INFO'] = env['PATH_INFO'][8:]
 31                 return trac_app(env, start_response)
 32         elif env['PATH_INFO'].startswith('/py/test'):
 33                 start_response('200 OK', [('Content-Type', 'text/plain')])
 34                 return [tmp]
 35         else:
 36                 return app(env, start_response)

Original issue reported on code.google.com by huayang...@gmail.com on 9 Mar 2012 at 4:06

GoogleCodeExporter commented 8 years ago
By using the paste http server the same issue happens, too.

Original comment by huayang...@gmail.com on 9 Mar 2012 at 4:12