def http_request(method, url, session=requests, **kwargs):
 kwargs.setdefault('timeout', 30.0)
 kwargs.setdefault('verify', False)
 try:
  return getattr(session, method.lower())(url, **kwargs)
 except (requests.exceptions.MissingSchema, requests.exceptions.InvalidSchema):
  print_error('Invalid URL format: {}'.format(url))
  return
 except requests.exceptions.ConnectionError:
  print_error('Connection error: {}'.format(url))
  return
 except requests.RequestException as error:
  print_error(error)
  return
 except socket.error as err:
  print_error(err)
  return
 except KeyboardInterrupt:
  print_info()
  print_status('Module has been stopped')

def http_request ( method , url , session = requests , ** kwargs ) : kwargs . setdefault ( 'timeout' , 30.0 ) kwargs . setdefault ( 'verify' , False ) try : return getattr ( session , method . lower ( ) ) ( url , ** kwargs ) except ( requests . exceptions . MissingSchema , requests . exceptions . InvalidSchema ) : print_error ( 'Invalid URL format: {}' . format ( url ) ) return except requests . exceptions . ConnectionError : print_error ( 'Connection error: {}' . format ( url ) ) return except requests . RequestException as error : print_error ( error ) return except socket . error as err : print_error ( err ) return except KeyboardInterrupt : print_info ( ) print_status ( 'Module has been stopped' )
wrapper for requests silencing exceptions a little bit .