def server_message(response):
 message = None
 if (response.headers.get('content-type') and ('text/html' in response.headers.get('content-type'))):
  try:
   soup = BeautifulSoup(response.content, 'html5lib')
  except Exception:
   pass
  message = soup.find('body')
  elements = ('header', 'script', 'footer', 'nav', 'input', 'textarea')
  for element in elements:
   for tag in soup.find_all(element):
    tag.replaceWith('')
  message = (message.text if message else soup.text)
  message = message.strip()
 if (message is None):
  message = response.content.strip()
 if message:
  if (len(message) > 150):
   message = (message[:150] + '...')
  logger.debug('Server responded with message: %s', message)

def server_message ( response ) : message = None if ( response . headers . get ( 'content-type' ) and ( 'text/html' in response . headers . get ( 'content-type' ) ) ) : try : soup = BeautifulSoup ( response . content , 'html5lib' ) except Exception : pass message = soup . find ( 'body' ) elements = ( 'header' , 'script' , 'footer' , 'nav' , 'input' , 'textarea' ) for element in elements : for tag in soup . find_all ( element ) : tag . replaceWith ( '' ) message = ( message . text if message else soup . text ) message = message . strip ( ) if ( message is None ) : message = response . content . strip ( ) if message : if ( len ( message ) > 150 ) : message = ( message [ : 150 ] + '...' ) logger . debug ( 'Server responded with message: %s' , message )
extract server message from response and log in to logger with debug level .