2012-08-04 131 views
-2

当我尝试将信息存储在谷歌应用程序引擎的数据库,我得到这个错误GAE蟒蛇ASCII编码解码器倾斜解码字节2

Traceback (most recent call last): 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1536, in __call__ 
    rv = self.handle_exception(request, response, e) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1530, in __call__ 
    rv = self.router.dispatch(request, response) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1278, in default_dispatcher 
    return route.handler_adapter(request, response) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 1102, in __call__ 
    return handler.dispatch() 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 572, in dispatch 
    return self.handle_exception(e, self.app.debug) 
    File "/base/python27_runtime/python27_lib/versions/third_party/webapp2-2.5.1/webapp2.py", line 570, in dispatch 
    return method(*args, **kwargs) 
    File "/base/data/home/apps/s~nothing-but-net/1.360803849981021046/main.py", line 460, in get 
    blchrlinks(True, a) 
    File "/base/data/home/apps/s~nothing-but-net/1.360803849981021046/main.py", line 282, in blchrlinks 
    b.put() 
    File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 1074, in put 
    return datastore.Put(self._entity, **kwargs) 
    File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 579, in Put 
    return PutAsync(entities, **kwargs).get_result() 
    File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 556, in PutAsync 
    return _GetConnection().async_put(config, entities, local_extra_hook) 
    File "/base/python27_runtime/python27_lib/versions/1/google/appengine/datastore/datastore_rpc.py", line 1552, in async_put 
    pbs = [self.__adapter.entity_to_pb(entity) for entity in entities] 
    File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 344, in entity_to_pb 
    return entity._ToPb() 
    File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 1025, in _ToPb 
    properties = datastore_types.ToPropertyPb(name, values) 
    File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore_types.py", line 1745, in ToPropertyPb 
    pbvalue = pack_prop(name, v, pb.mutable_value()) 
    File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore_types.py", line 1556, in PackString 
    pbvalue.set_stringvalue(unicode(value).encode('utf-8')) 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 57: ordinal not in range(128) 
+1

你好像误解了SO的工作原理。您将所有相关信息以及问题都放在问题框中,我们用它来回答问题。现在,你既没有所有的相关信息,也没有问题。 – 2012-08-04 17:03:04

+0

可能重复的[gae python ascii编解码器不能解码字节](http://stackoverflow.com/questions/11789770/gae-python-ascii-codec-cant-decode-byte) – Flexo 2013-01-20 20:41:02

回答

1

您正在尝试使用ASCII编解码器解码非ASCII字符。你需要知道你的输入字符是如何编码的。

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 57: ordinal not in range(128) 

与流行的看法相反,二进制数据没有内在含义。它只有它的作者指定的含义。

1

听起来像你有一个Unicode编码错误,但你没有足够的信息来帮助找出问题所在。

两件事情要尝试。

1)# -*- encoding: utf-8 -*-在其中呼叫正在取得的文件的顶部(如果你有在文件中的Unicode如☃或€

2)确保您发送的Unicode到数据库而不是一个str。否则这种情况

>>> x = eval("'Capit\\xc3\\xa1n\\n'") 
>>> x 
'Capit\xc3\xa1n\n' 
>>> x[5] 
'\xc3' 
>>> len(x[5]) 
1 

正如你可以看到它的转向多位的unicode成\ XC3 \ xa1n成2个字符,其中,所述第一超出范围为ASCII代,因为它是UTF-8编码的一个比特(这就是为什么正常ascii主要在UTF-8工作)

但是,请提供更多的信息,我们可以看看。

相关问题