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

Created on 14 Oct 2020  路  9Comments  路  Source: GoogleCloudPlatform/gsutil

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.

Most helpful comment

export CLOUDSDK_PYTHON=python2.7

All 9 comments

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.

export CLOUDSDK_PYTHON=python2.7

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.

export CLOUDSDK_PYTHON=python2.7

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

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.

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

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

This was also reported here https://github.com/GoogleCloudPlatform/gsutil/issues/1284. Reopening this one.

@ayy-em , decodestring function call has been already replaced with b64decode https://github.com/GoogleCloudPlatform/gsutil/blob/eadfefb0abcddef32d20b44c948c6eb3182aedab/gslib/utils/encryption_helper.py#L152

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

khavishbhundoo picture khavishbhundoo  路  7Comments

dweekly picture dweekly  路  6Comments

tedsta picture tedsta  路  8Comments

gdaughenbaugh picture gdaughenbaugh  路  6Comments

nathankw picture nathankw  路  6Comments