Skip to content

fix(http): use b64encode with explicit encode/decode for Python 3 - #137

Open
C1-BA-B1-F3 wants to merge 1 commit into
geopython:masterfrom
C1-BA-B1-F3:fix/base64-python3
Open

C1-BA-B1-F3 wants to merge 1 commit into
geopython:masterfrom
C1-BA-B1-F3:fix/base64-python3

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Summary

base64.encodestring was removed in Python 3.9 and expected a str in earlier Python 3 versions (raising TypeError: expected bytes-like object, not str). This is a leftover from the Python 2 to 3 migration.

Fix

Replace base64.encodestring(...) with base64.b64encode(...encode('utf-8')).decode('utf-8') in both HTTP input and output modules.

Test plan

  • base64.b64encode('user:pass'.encode()).decode() produces the expected dXNlcjpwYXNz.

Fixes #130

base64.encodestring was removed in Python 3.9 and expected a str in
Python 3 (raising TypeError: expected bytes-like object, not str).
Use base64.b64encode with explicit UTF-8 encode/decode, which works
on all Python 3 versions.

Fixes geopython#130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Base64 encoding in HTTP Auth modules requires Python3 Unicode string handling

1 participant