2

Python を使用した GAE では、urlfetch を使用して Flickr から json 文字列を取得しています。実稼働サーバーで json.loads を使用してその文字列をロードしようとすると、「raised ValueError(Unpaired high surrogate)」という例外がスローされます。

開発コンソールで文字列を json.loads しようとすると、期待どおりに dict に読み込まれます (以下を参照)。同じコードを使用して、Flickr から他のいくつかの json 文字列を正常にロードしました。以下の json 文字列には、運用サーバーでのみ ValueError 例外をスローするものがあります。

import json

s = """{"photo":{"id":"191019103", "secret":"d7a8bb95bc", "server":"72", "farm":1, "dateuploaded":"1153079847", "isfavorite":0, "license":"1", "safety_level":"0", "rotation":0, "originalsecret":"d7a8bb95bc", "originalformat":"jpg", "owner":{"nsid":"13968020@N00", "username":"\ud800dc80 jgraham", "realname":"", "location":"", "iconserver":"38", "iconfarm":1}, "title":{"_content":"By the Year 2000 All Our Food Will be in the Form of Tiny Pills"}, "description":{"_content":""}, "visibility":{"ispublic":1, "isfriend":0, "isfamily":0}, "dates":{"posted":"1153079847", "taken":"2006-07-15 14:31:16", "takengranularity":"0", "lastupdate":"1282690106"}, "views":"984", "editability":{"cancomment":0, "canaddmeta":0}, "publiceditability":{"cancomment":1, "canaddmeta":0}, "usage":{"candownload":1, "canblog":0, "canprint":0, "canshare":1}, "comments":{"_content":"18"}, "notes":{"note":[]}, "people":{"haspeople":0}, "tags":{"tag":[{"id":"1207251-191019103-2909", "author":"13968020@N00", "raw":"Birmingham", "_content":"birmingham", "machine_tag":0}, {"id":"1207251-191019103-77552", "author":"13968020@N00", "raw":"Bullring", "_content":"bullring", "machine_tag":0}, {"id":"1207251-191019103-463", "author":"13968020@N00", "raw":"Abstract", "_content":"abstract", "machine_tag":0}, {"id":"1207251-191019103-1174", "author":"13968020@N00", "raw":"Architecture", "_content":"architecture", "machine_tag":0}, {"id":"1207251-191019103-141", "author":"13968020@N00", "raw":"Blue", "_content":"blue", "machine_tag":0}, {"id":"1207251-191019103-2194948", "author":"13968020@N00", "raw":"i500", "_content":"i500", "machine_tag":0}, {"id":"1207251-191019103-11820", "author":"13968020@N00", "raw":"Explore", "_content":"explore", "machine_tag":0}, {"id":"1207251-191019103-3254511", "author":"13968020@N00", "raw":"utata_feature", "_content":"utatafeature", "machine_tag":0}]}, "urls":{"url":[{"type":"photopage", "_content":"http:\/\/www.flickr.com\/photos\/jgraham\/191019103\/"}]}, "media":"photo"}, "stat":"ok"}"""

print json.loads(s) #prints dict
4

4 に答える 4

0

この問題は Python 2.7.7 以降で修正されました。

http://bugs.python.org/issue11489

https://hg.python.org/cpython/raw-file/v2.7.7/Misc/NEWS

ただし、2016 年 3 月 11 日の時点で、Google App Engine は本番環境で Python 2.7.5 を実行しており、json モジュールへのパッチ 11489 はありません。

この問題について GAE サポート チームに話を聞いたところ、Google Public Issue Tracker が提出されました。

https://code.google.com/p/googleappengine/issues/detail?id=12823

当面は、 mihaicc が提案するように、標準の json モジュールの代わりに simplejson モジュールを使用する最善の解決策のようです。simplejson バージョン 3.8.2 をテストしましたが、どちらも GAE で動作し、エラーは発生しませんでした。

于 2016-03-11T19:29:47.470 に答える