# Error while executing command via Rancher API

**URL:** <https://forums.suse.com/t/error-while-executing-command-via-rancher-api/6570>\
**Category:** Rancher 1.x\
**Created:** [June 7, 2017, 12:34am UTC](https://forums.suse.com/t/error-while-executing-command-via-rancher-api/6570 "2017-06-07T00:34:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![purvilkamdar](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@purvilkamdar](https://forums.suse.com/u/purvilkamdar)\
**Post date:** [June 7, 2017, 12:34am UTC](https://forums.suse.com/t/error-while-executing-command-via-rancher-api/6570/1 "2017-06-07T00:34:11Z")

</div>

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()
