Reputation: 157
I'm trying to convert from python 2.7 to 3.4 and get the following error when trying to use b64encode
:
from base64 import b64encode
username = 'manager'
password = 'test.manager'
headers = {"Authorization": " Basic " + b64encode(username + ":" + password), "Content-Type": "application/json"}
Error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\python34\Lib\base64.py", line 62, in b64encode
encoded = binascii.b2a_base64(s)[:-1]
**TypeError: 'str' does not support the buffer interface**
Upvotes: 1
Views: 1228
Reputation: 9609
Use bytes
objects instead:
username = b'manager'
password = b'test.manager'
headers = {"Authorization": b" Basic " + b64encode(username + b":" + password), "Content-Type": "application/json"}
Upvotes: 1