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')}
2
  • 1
    possible duplicate of bytes encoding python Commented Nov 9, 2016 at 9:44
  • Use b'Someuser:Somepassword' if this is a hardcoded literal Commented Nov 9, 2016 at 11:02

2 Answers 2

4

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

bytes("mystring", "ascii")
Sign up to request clarification or add additional context in comments.

Comments

1

I guess you need something like this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.