- http.request('POST',command_url,headers=my_headers,body=command.encode('UTF-8'))
- if reply_url:
- sleep(0.5)
- res="NULL"
- for i in range(api_attempts):
- try:
- if command_user:
- my_headers = urllib3.util.make_headers(basic_auth=command_user+':'+command_pwd)
- else:
- my_headers = urllib3.util.make_headers()
- req=http.request('GET',reply_url,headers=my_headers).data
- res = json.loads(req)['state'].strip()
- if config["debug"]:
- print(res)
- if not(res == 'NULL'):
- break
- sleep(1)
- except KeyboardInterrupt:
- raise
- except:
- sleep(1)
- if res and not(res=="NULL"):
- PlayBack(pyaud, res, mic=mic)
- elif res=="NULL":
- PlayBack(pyaud, "Сервер не ответил", mic=mic)
- if command_user:
- my_headers = urllib3.util.make_headers(basic_auth=command_user+':'+command_pwd)
+ if config["debug"]:
+ print('Sending command')
+ sent = False
+ for i in range(api_attempts):
+ try:
+ http.request('POST',command_url,headers=my_headers,body=command.encode('UTF-8'))
+ sent = True
+ break
+ except Exception as e:
+ print('Exception: '+str(e))
+ sleep(0.5)
+ if sent:
+ if config["debug"]:
+ print('Command sent')
+ if reply_url:
+ sleep(0.5)
+ res="NULL"
+ for i in range(api_attempts):
+ try:
+ if command_user:
+ my_headers = urllib3.util.make_headers(basic_auth=command_user+':'+command_pwd)
+ else:
+ my_headers = urllib3.util.make_headers()
+ req=http.request('GET',reply_url,headers=my_headers).data
+ res = json.loads(req)['state'].strip()
+ if config["debug"]:
+ print(res)
+ if not(res == 'NULL'):
+ break
+ sleep(1)
+ except KeyboardInterrupt:
+ raise
+ except Exception as e:
+ print('Exception: '+str(e))
+ sleep(1)
+ if res and not(res=="NULL"):
+ PlayBack(pyaud, res, mic=mic)
+ elif res=="NULL":
+ PlayBack(pyaud, "Сервер не ответил", mic=mic)
+ if command_user:
+ my_headers = urllib3.util.make_headers(basic_auth=command_user+':'+command_pwd)
+ else:
+ my_headers = urllib3.util.make_headers()
+ my_headers['Content-Type']='text/plain'
+ my_headers['Accept']='apllication/json'
+ command=""
+ http.request('POST',command_url, headers=my_headers, body=command.encode('UTF-8'))