def _req_json_rpc(url, method, *args, **kwargs):
 data = json.dumps({'method': method, 'params': args})
 try:
  res = requests.post(url, data=data, timeout=5, **kwargs)
 except requests.exceptions.Timeout:
  _LOGGER.exception('Connection to the router timed out')
  return
 if (res.status_code == 200):
  try:
   result = res.json()
  except ValueError:
   _LOGGER.exception('Failed to parse response from luci')
   return
  try:
   return result['result']
  except KeyError:
   _LOGGER.exception('No result in response from luci')
   return
 elif (res.status_code == 401):
  _LOGGER.exception('Failed to authenticate, please check your username and password')
  return
 else:
  _LOGGER.error('Invalid response from luci: %s', res)

def _req_json_rpc ( url , method , * args , ** kwargs ) : data = json . dumps ( { 'method' : method , 'params' : args } ) try : res = requests . post ( url , data = data , timeout = 5 , ** kwargs ) except requests . exceptions . Timeout : _LOGGER . exception ( 'Connection to the router timed out' ) return if ( res . status_code == 200 ) : try : result = res . json ( ) except ValueError : _LOGGER . exception ( 'Failed to parse response from luci' ) return try : return result [ 'result' ] except KeyError : _LOGGER . exception ( 'No result in response from luci' ) return elif ( res . status_code == 401 ) : _LOGGER . exception ( 'Failed to authenticate, please check your username and password' ) return else : _LOGGER . error ( 'Invalid response from luci: %s' , res )
perform one json rpc operation .