Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python 3 string argument without an encoding

Tags:

python

string

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')}
like image 653
Alexander Wilhelm Avatar asked Jul 25 '26 04:07

Alexander Wilhelm


2 Answers

The bytes() class constructor now expects the encoding as second param. Example:

bytes("mystring", "ascii")
like image 197
Hubert Grzeskowiak Avatar answered Jul 26 '26 20:07

Hubert Grzeskowiak


I guess you need something like this:

headers = {'Authorization' : 'Basic ' + base64.b64encode(bytes('Someuser:Somepassword','ascii')).decode('ascii')}
like image 23
milos.ai Avatar answered Jul 26 '26 18:07

milos.ai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!