def basic_auth_header(username, password):
 return (b('Basic %s') % base64.b64encode(to_bytes(('%s:%s' % (username, password)), errors='surrogate_or_strict')))

def basic_auth_header ( username , password ) : return ( b ( 'Basic %s' ) % base64 . b64encode ( to_bytes ( ( '%s:%s' % ( username , password ) ) , errors = 'surrogate_or_strict' ) ) )
takes a username and password and returns a byte string suitable for using as value of an authorization header to do basic auth .