basic auth request

Robin Becker robin at reportlab.com
Tue Aug 17 05:20:37 EDT 2021


While porting an ap from python2.7 to python3 I see this

	base64string = base64.b64encode('%s:%s' % (wsemail, wspassword))
	request.add_header("Authorization", "Basic %s" % base64string)

in python3.x I find this works

	base64string = base64.b64encode(('%s:%s' % (wsemail, wspassword)).encode('ascii')).decode('ascii')
	request.add_header("Authorization", "Basic %s" % base64string)

but I find the conversion to and from ascii irksome. Is there a more direct way to create the basic auth value?

As an additional issue I find I have no clear idea what encoding is allowed for the components of a basic auth input.
--
Robin Becker



More information about the Python-list mailing list