def ValidHeadersRewriter(response):
 for (key, value) in response.headers.items():
  try:
   key.decode('ascii')
   value.decode('ascii')
  except UnicodeDecodeError:
   del response.headers[key]

def ValidHeadersRewriter ( response ) : for ( key , value ) in response . headers . items ( ) : try : key . decode ( 'ascii' ) value . decode ( 'ascii' ) except UnicodeDecodeError : del response . headers [ key ]
remove invalid response headers .