【问题标题】:GAE: How to use unicode characters in urlGAE:如何在 url 中使用 unicode 字符
【发布时间】:2013-03-20 15:55:34
【问题描述】:

我刚刚将 GAE 升级到 1.7.6 (python 2.7)。我的应用在 URL 中使用了一些西班牙语字符(例如“españa”或“cádiz”等词)。到目前为止,我与他们打交道没有任何问题。但是,升级后,每当我在我的网址中引入特殊字符时,我都会收到错误消息并且我的应用程序崩溃:

ProgrammingError('You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.',)
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 1302, in communicate
req.respond()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 831, in respond
self.server.gateway(self).respond()
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/cherrypy/cherrypy/wsgiserver/wsgiserver2.py", line 2115, in respond
response = self.req.server.wsgi_app(self.env, self.start_response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/wsgi_server.py", line 230, in __call__
return app(environ, start_response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/server.py", line 1114, in __call__
return self._handle_request(environ, start_response)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/devappserver2/server.py", line 512, in _handle_request
http_version=http_version)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/apiproxy_stub.py", line 160, in WrappedMethod
return method(self, *args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/logservice/logservice_stub.py", line 151, in start_request
host, start_time, method, resource, http_version))
ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

我编写了一个简单的应用程序来调试问题,但没有积极的结果:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import webapp2

class MainHandler(webapp2.RequestHandler):
    def get(self):
        self.response.write('Hello world!')

class MyHandler(webapp2.RequestHandler):
  def get(self, param):
    self.response.write(param)

app = webapp2.WSGIApplication([
    ('/', MainHandler),
    ('/(.*)', MyHandler)
], debug=True)

当访问 URL“/hola”时,响应如预期,浏览器显示“hola”字样。但是,当访问“/españa”甚至“/espa%C3%B1a”时,开发服务器会崩溃并出现上述错误。

注意这个错误只发生在开发中,我猜是和新的sqlite数据库有关;但是,在前面的示例中,我根本没有使用数据库!

有什么想法吗?请帮忙!

【问题讨论】:

    标签: google-app-engine python-2.7 sqlite url-routing


    【解决方案1】:

    这似乎是开发服务器的一个错误。目前最好的办法是在 GAE 错误跟踪器上为该错误加注星标:GAE bug - url's with unicode characters

    希望如果更多人“star”它,他们会更快地解决这个问题。

    【讨论】:

      猜你喜欢
      • 2013-12-29
      • 2018-07-02
      • 1970-01-01
      • 2013-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-26
      相关资源
      最近更新 更多