google-app-engine - GAE : How to use unicode characters in url

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

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

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数据库有关;但是,在前面的示例中,我根本没有使用数据库!

有什么想法吗?请帮忙!

最佳答案

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

如果有更多人“加注星标”,希望他们能更快地解决这个问题。

关于google-app-engine - GAE : How to use unicode characters in url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15528518/

相关文章:

python - 如何使用大量 bool 属性创建高效的 Google-App-Engine 架构

python - NDB 模型使用数组过滤器查询键 ID

sqlite - 如何在单声道下使用System.Data.SQLite?

python - 无法使用for循环处理大量数据

python,sqlite错误?数据库被锁定?但不是吗?

java - 在插件 com.google.appengine :appengine-maven-plugin 中找不到目标 'run'

python - 使用循环在 "start_urls"函数中输入值以从 csv 输入值

python - 在 Python 中,如何将 `datetime` 对象转换为秒?

python - Paramiko/加密弃用警告 : CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers

java - 在 Google App Engine (localhost) 上的 Jetty 上调试应用程序