I am having a hard time passing information properly from a python script to a rails app through web sockets (using Action Cable).
I want to use input information in a python dictionary like this :
message = {
'command':"subscribe",
'identifier':{
'channel': 'RaspChannel',
'rasp_local_id': '1'
}
}
It should then be converted into JSON, go through a web socket set by Action Cable, then parsed into a ruby hash on the server side.
For some reason, I only made it work by sending a plain string through the socket :
'{"command":"subscribe","identifier":"{\\"channel\\":\\"RaspChannel\\", \\"rasp_local_id\\": \\"1\\"}"}'
But I could not make it work by sending json.dumps(message)
even though it returned something that looked pretty good to me :
{"command": "subscribe", "identifier": {"channel": "RaspChannel", "rasp_local_id": "1"}}
I suppose action cable protocol uses the classic ruby JSON.parse
method on the json string it receives as input, and for some reason, it always throws a parsing error, unless I use the plain string I mentioned above.
However, as I want to make the message more complicated, it would be better if I could make it work with actual Python dictionaries from the beginning.
Any idea on what I am missing ?