I'm trying to create an HTTP/2 connection using Python, Requests, and the Hyper HTTP20Adapter (for HTTP/2 support) to AVS (Version 20160207 of the API). I asked a similar question here, and determined that my main problem was coming from Requests not supporting HTTP/2 -- I believe I have fixed that with my use of the Hyper module.
Amazon's instructions say to GET
a down channel stream, then on that same connection, POST
a SynchronizeState
event.
This is my attempt at sending the two requests:
downstream = requests.Session()
downstream.mount('https://avs-alexa-na.amazon.com', HTTP20Adapter())
qheader = {"authorization": "Bearer " + ACCESS_KEY}
sheader = {"authorization": "Bearer " + ACCESS_KEY, "Content-Disposition": "form-data; name=metadata","Content-Type": "application/json; charset=UTF-8"}
spayload = {"context": [],"event": {"header":{"namespace":"System","name":"SynchronizeState","messageId":"SyncState",},"payload": {}}}
q = downstream.get("https://avs-alexa-na.amazon.com/v20160207/directives", headers=qheader, stream=True)
s = downstream.post("https://avs-alexa-na.amazon.com/v20160207/events", headers=sheader, data=json.dumps(spayload)
However, I'm consistently getting this error message:
INVALID_REQUEST_EXCEPTION, description: No multipart body found in the payload.
This persists even if I take out the data=json.dumps(spayload)
line in the post
request and replace it with json = spayload
.
I have two main questions:
1) I'm not sure that I'm making both requests on "the same connection" as instructed. Am I (I thought that requests.Session()
took care of that, but...)? If not, how would I do that?
2) How do I resolve the "No multipart body found in payload" message? I sent their example SynchronizeState event exactly, and it specifically said to include an empty payload.
Thanks in advance for the help! Anything is appreciated!