简体   繁体   English

gae python ascii编解码器无法解码字节

[英]gae python ascii codec cant decode byte

When I run my application, which finds links, checks if they exist in the database, and adds them to the database, I get an error. 当我运行我的应用程序,它找到链接,检查它们是否存在于数据库中,并将它们添加到数据库时,我收到一个错误。

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.360769209191920043/main.py", line 460, in get
    blchrlinks(True, a)
  File "/base/data/home/apps/s~nothing-but-net/1.360769209191920043/main.py", line 271, in blchrlinks
    if Articles.by_name(title):
  File "/base/data/home/apps/s~nothing-but-net/1.360769209191920043/main.py", line 498, in by_name
    u = Articles.all().filter("name =", name).get()
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 2099, in get
    results = self.run(limit=1, **kwargs)
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/ext/db/__init__.py", line 2063, in run
    iterator = raw_query.Run(**kwargs)
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 1622, in Run
    itr = Iterator(self.GetBatcher(config=config))
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 1601, in GetBatcher
    return self.GetQuery().run(_GetConnection(), query_options)
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 1490, in GetQuery
    filter_predicate=self.GetFilterPredicate(),
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/api/datastore.py", line 1534, in GetFilterPredicate
    property_filters.append(datastore_query.make_filter(name, op, values))
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/datastore/datastore_query.py", line 107, in make_filter
    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)

My code for by_name is: 我的by_name代码是:

def by_name(cls, name):
    u = Articles.all().filter("name =", name).get()
    return u

As the last line of the stack trace shows, it's trying to convert the value to unicode first and then encoding it as utf-8. 正如堆栈跟踪的最后一行所示,它试图先将值转换为unicode,然后将其编码为utf-8。 However, the (implicit) conversion is using ascii, which is not enough for your string. 但是,(隐式)转换使用ascii,这对于您的字符串是不够的。 You could try converting it to unicode yourself, using the right encoding, before passing it to filter . 在将其传递给filter之前,您可以尝试使用正确的编码将其转换为unicode。 Example: 例:

u = Articles.all().filter("name =", name.decode('utf-8')).get()

(remember that you need to provide the correct encoding; if name is not a UTF-8 string, but a Cp1252, ISO-Latin or something else, you need to specify that in the decode call) (记住你需要提供正确的编码;如果name不是UTF-8字符串,而是Cp1252,ISO-Latin或其他东西,你需要在decode调用中指定)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ascii编解码器无法解码字节0xe9 - ascii codec cant decode byte 0xe9 Python json忽略非ascii字符UnicodeDecodeError:'ascii'编解码器无法解码字节 - Python json Ignoring non-ascii chars UnicodeDecodeError: 'ascii' codec cant decode byte UnicodeDecodeError:'ascii' 编解码器无法解码位置 14 中的字节 0xe2:在 GAE python 中序号不在范围内(128)? - UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 14: ordinal not in range(128) in GAE python? Python:“ ascii”编解码器无法解码字节 - Python: 'ascii' codec can't decode byte Python - 'ascii'编解码器无法解码字节 - Python - 'ascii' codec can't decode byte Python - “ascii”编解码器无法解码字节 - Python - 'ascii' codec can't decode byte Python 2.7 UnicodeDecodeError:'ascii'编解码器无法解码字节 - Python 2.7 UnicodeDecodeError: 'ascii' codec can't decode byte Python(nltk)-UnicodeDecodeError:“ ascii”编解码器无法解码字节 - Python (nltk) - UnicodeDecodeError: 'ascii' codec can't decode byte Python - 'ascii'编解码器无法解码byte \ xbd的位置 - Python - 'ascii' codec can't decode byte \xbd in position UnicodeDecodeError:“ ascii”编解码器无法在Python中解码字节 - UnicodeDecodeError: 'ascii' codec can't decode byte in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM