2012-08-03 3 views
1

링크가있는 응용 프로그램을 실행하여 데이터베이스에 있는지 확인한 다음 데이터베이스에 추가하면 오류가 발생합니다. by_name에 대한gae 파이썬 아스키 코덱 캔트 디코드 바이트

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) 

내 코드는 다음과 같습니다

스택 추적 쇼의 마지막 줄에
def by_name(cls, name): 
    u = Articles.all().filter("name =", name).get() 
    return u 

답변

4

는 먼저 다음 UTF-8로 인코딩 유니 코드로 값을 변환하려고. 그러나 (암시 적) 변환은 ascii를 사용하는데, 이는 문자열에 충분하지 않습니다. filter에 전달하기 전에 올바른 인코딩을 사용하여 유니 코드로 변환 해 볼 수 있습니다. 예 :

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

(당신이 올바른 인코딩을 제공해야 기억, name은 UTF-8 문자열이 아닌,하지만 Cp1252를, ISO 라틴어 또는 뭔가 다른, 당신은에 지정해야하는 경우 decode 전화)