我正在尝试将以下 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 服务器?谢谢你!