Alexander Wilhelm Alexander Wilhelm - 29 days ago 10
Python Question

python 3 string argument without an encoding

This code worked with Python 2.7 but on Python 3.4 I get "string argument without an encoding" error

headers = {'Authorization' : 'Basic ' + base64.b64encode(bytes('Someuser:Somepassword')).encode('ascii')}

Answer

I guess you need something like this:

headers = {'Authorization' : 'Basic ' + base64.b64encode(bytes('Someuser:Somepassword','ascii')).decode('ascii')}