LoginSignup
6
6

More than 5 years have passed since last update.

GAE/Pythonのローカル環境でfull text searchが動かない場合のpatch

Last updated at Posted at 2014-07-23

こんなエラーが。

  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/api/search/search.py", line 1121, in _DecodeUTF8
    return pb_value.decode('utf-8')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 158-159: invalid continuation byte

unicode周りのバグっぽいけどデプロイするとなぜか動く。

これを参考
https://code.google.com/p/googleappengine/issues/detail?id=9335
にしたけど、このリンク先のままだと動かなかくて以下なような感じに(ライブラリ直接さわってしまってるので注意)。

/google_appengine/google/appengine/_internal/antlr3/streams.py
 335   >.# The data being scanned
 336         data = data.encode("utf-8") # これを追加
 337         self.strdata = unicode(data, errors="replace")
 338         self.data = [ord(c) for c in self.strdata]
/usr/local/google_appengine/google/appengine/api/search/search.py
 1118   #def _DecodeUTF8(pb_value):
 1119   #  """Decodes a UTF-8 encoded string into unicode."""
 1120   #  if pb_value is not None:
 1121   #    return pb_value.decode('utf-8')
 1122   #  return None
 1123   
 1124   def _DecodeUTF8(pb_value): #これを置き換え
 1125     """Decodes a UTF-8 encoded string into unicode."""
 1126     if pb_value is not None:
 1127       return pb_value.decode('utf-8', errors='replace') if not isinstance(pb_value, unicode) else pb_value

とりあえず。

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6