Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encountered an error on Python 3.9 - AttributeError: module 'base64' has no attribute 'decodestring' #1118

Open
chubillkelvin opened this issue Oct 14, 2020 · 9 comments · Fixed by #1177

Comments

@chubillkelvin
Copy link

Microsoft's app center has recently updated to Python 3.9, and I encountered the follow error when running gsutil on it:

Traceback (most recent call last):
  File "/usr/local/bin/gsutil", line 5, in <module>
    from gslib.__main__ import main
  File "/usr/local/lib/python3.9/site-packages/gslib/__main__.py", line 92, in <module>
    from gslib.command_runner import CommandRunner
  File "/usr/local/lib/python3.9/site-packages/gslib/command_runner.py", line 64, in <module>
    from gslib.tests.util import HAS_NON_DEFAULT_GS_HOST
  File "/usr/local/lib/python3.9/site-packages/gslib/tests/util.py", line 126, in <module>
    TEST_ENCRYPTION_KEY1_SHA256_B64 = Base64Sha256FromBase64EncryptionKey(
  File "/usr/local/lib/python3.9/site-packages/gslib/utils/encryption_helper.py", line 152, in Base64Sha256FromBase64EncryptionKey
    decoded_bytes = base64.decodestring(csek_encryption_key)
AttributeError: module 'base64' has no attribute 'decodestring'

This error is triggered with gsutil -o Credentials:gs_service_key_file=./mykey.json cp src_url dist_url command.

Any thoughts on how to get this command work on Python 3.9? Thank you.

@chubillkelvin
Copy link
Author

If anyone is encountering the same issue with app center, I managed to find a temporary fix by doing
python3.8 -m pip install gsutil
so that it uses python 3.8 to run gsutil.

However, it still doesn't fix the problem with running gsutil on python 3.9.

@Nakilon
Copy link
Contributor

Nakilon commented Nov 12, 2020

export CLOUDSDK_PYTHON=python2.7

@surferjeff
Copy link

export CLOUDSDK_PYTHON=python2.7

I tried this, and it gsutil cp uploaded my wasm file as application/octet rather than application/wasm, which broke my app. So be careful, and prefer

export CLOUDSDK_PYTHON=python3.8

if you have 3.8 installed on your system.

@fabiotnt
Copy link

export CLOUDSDK_PYTHON=python2.7

I have added this code inside ~/.zshrc file on my Mac.
Fixed. Thanks for that

@dilipped
Copy link
Collaborator

This issue has been fixed in gsutil v4.55 which was released with Cloud SDK 319.0.0. Feel free to open it again if the issue persists.

@abonander
Copy link

abonander commented Jan 9, 2021

I just ran into a similar issue with gsutil v4.57 from the AUR: https://aur.archlinux.org/packages/google-cloud-sdk

Only this time, it's module 'base64' has no attribute 'encodestring'.

If it matters, I have gcloud config set pass_credentials_to_gsutil false and authenticated with gsutil config -a

@ayy-em
Copy link

ayy-em commented May 31, 2021

just encountered AttributeError: module 'base64' has no attribute 'decodestring' when trying to upload files in my bucket using CLI running Cloud SDK 342.0.0

@dilipped
Copy link
Collaborator

dilipped commented Jun 1, 2021

This was also reported here #1284. Reopening this one.

@dilipped
Copy link
Collaborator

dilipped commented Jun 1, 2021

@ayy-em , decodestring function call has been already replaced with b64decode

decoded_bytes = base64.b64decode(csek_encryption_key)

Can you please check your gsutil version by running gsutil ver -l?

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 a pull request may close this issue.

7 participants