Error while executing command via Rancher API

I am trying to fire the following python script to execute the commands inside a Rancher container. I am preparing automation scripts for HA testing of Rancher deployment. So, when I fire the following script in python, I do not get any response in the ws.recv() method. I don’t know if the command gets fired or not, if it gets fired, how do I display the output of the command. Also if I use ws.recv_frame(), I get(8, b’\x03\xe8’) as the response. What does he value of this tuple mean? I am very new to Rancher. Here is my python script:

import docker
import requests
import os
import time
import websockets
import websocket

Access_Key=Access_key (My Access_key)
Secret_Key=Secret_key (My Secret_key)

def main():
url=url (My url)
containers='containers/'
container_id=‘1i203’

headers = {
    'Content-Type': 'application/json',
}

params = (
    ('action', 'execute'),
)
data = '{\n\t"attachStdin": true,\n\t"attachStdout": true,\n\t"command": [\n\t\t"ping",\n\t\t"a2"\n\t],\n\t"tty": true\n}'


response=requests.post(url+containers+container_id, headers=headers, params=params,
              data=data, auth=(Access_Key, Secret_Key))

print ("Response="+str(response.json()))

returned_data = response.json()
sock_url = str(returned_data['url'])
token = str(returned_data['token'])
print("sock_url=" + sock_url)
print("token=" + token)
sock_headers = {
    'Authorization': 'Bearer ' + token,
}
ws = websocket.create_connection(str(returned_data['url']), header=sock_headers)


print("Sock_object_headers=" + str(ws.headers))

da = ws.recv()
print("Web_sockets recieve=" + str(da))
ws.close()

if name == ‘main’:
main()