3
我剛剛將GAE升級到1.7.6(python 2.7)。我的應用在網址中使用了一些西班牙文字符(如「españa」或「cádiz」)。到目前爲止,我沒有遇到任何問題。然而,升級後,我keed有和錯誤消息,我的應用程序崩潰wenever我在URL引進特殊字符:GAE:如何在url中使用unicode字符
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數據庫有關;然而,在前面的例子中,我根本沒有使用數據庫!
任何想法?請幫忙!