次のcurlコマンドを変換して、urllib2経由で通知を送信しようとしています
curl -v -S -u devuser:devuser123 -F'notification={"applicationId":"4","schemaId":"14","topicId":"3","type":"USER"};type=application/json' -F'endpointKeyHash=lsXnYUbE31aCgN5NSsbcRMAZTgM=;type=text/plain' -F file={"message" : "Hello world!"} "http://localhost:8080/kaaAdmin/rest/api/sendUnicastNotification" | python -mjson.tool
そして、私は通知を送信するためにこのコードを書きます
import urllib2, base64
data = 'notification={"applicationId":"4","schemaId":"14","topicId":"3","type":"USER"};type=application/json&endpointKeyHash=xQXJ7OzFX4M6W5tl4sVTuWLTuzc=;type=text/plain&file={"message":"Hello world!"}'
url="http://localhost:8080/kaaAdmin/rest/api/sendUnicastNotification"
request = urllib2.Request(url, data)
#authentication part
base64string = base64.encodestring('%s:%s' % ('devuser', 'devuser123')).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
the_page = result.read()
しかし、このコードを実行すると、次のエラーが発生します
line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 415: Unsupported Media Type
問題はおそらくurllib2を介して複数のデータを送信することですが、urllib2を介してそのパラメーターをkaaサーバーに送信するにはどうすればよいですか? ありがとう!