Werkzeug/0.9.4 が原因だと思われる Flask-restful の動作がわかりませんでした。「=」を含む有効な JSON を POST しようとすると、Multidict を使用するとデータが壊れているようです。
これが私のテストJSONです:
{
"alert": {
"@id": "90",
"action": "hoojimaflip",
"fruit": {
"@bowl": "bananas",
"@protocol": "tcp"
},
"url": "https://this-is-a-sample/paramer?id=90"
}
}
これが POST メソッドです。
def post(self):
f1=open("./log", 'w+')
data = request.json
if not data:
# I know this is not equivalent to the JSON above.
# Just troubleshooting by dumping it all out.
data = request.form
print >>f1, data
return ('', 201)
application/json で cURL を使用して POST すると、問題ありません。request.data で POST された JSON を正しく取得します。後で JSON にレンダリングする必要がありますが、問題ありません。
{
u'alert': {
u'@id': u'90'
u'action': u'hoojimaflip',
u'fruit': {
u'@bowl': u'bananas',
u'@protocol': u'tcp'
},
u'url': u'https://this-is-a-sample/paramer?id=90',
}
}
application/x-www-form-urlencoded を使用して cURL 経由で投稿すると、request.form でデータを取得できるはずです。しかし、何かが私のデータを壊しているようです。
ImmutableMultiDict([('
{ "alert": {
"@id": "90",
"action": "hoojimaflip",
"fruit": {
"@bowl": "bananas",
"@protocol": "tcp"
},
"url": "https://this-is-a-sample/paramer?id', u'90"
}
}'
)])
「=」記号はある種のレコード セパレータとして使用されており、POST された JSON を壊しています。
誰にもアイデアはありますか?明らかな何かが欠けていますか?
ありがとう!