3

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')}
  • 1
    possible duplicate of [bytes encoding python](https://stackoverflow.com/questions/31161243/python-string-argument-without-an-encoding) – Vaulstein Nov 09 '16 at 09:44
  • Use `b'Someuser:Somepassword'` if this is a hardcoded literal – mata Nov 09 '16 at 11:02

2 Answers2

4

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

bytes("mystring", "ascii")
Hubert Grzeskowiak
  • 15,137
  • 5
  • 57
  • 74
1

I guess you need something like this:

headers = {'Authorization' : 'Basic ' + base64.b64encode(bytes('Someuser:Somepassword','ascii')).decode('ascii')}
milos.ai
  • 3,882
  • 7
  • 31
  • 33