gcloud crashed (UnicodeDecodeError)

2017-03-18 06:59:24 -0400

Today I was trying to install kubectl for gcloud (MacOS) using socks5 proxy

gcloud components install kubectl

And it gives me this error:

ERROR: gcloud crashed (UnicodeDecodeError): 'utf8' codec can't decode byte 0xbb in position 1: invalid start byte

After searching around the Internet found nothing useful. After enabled the stack trace printing in google-cloud-sdk/lib/googlecloudsdk/command_lib/crash_handling.py, I finally figured out the problem is coming from google-cloud-sdk/lib/third_party/socks/__init__.py

in __negotiatesocks5
req += struct.pack(">H", destport)

The req here sometimes is with the type of "unicode", instead of "str", while the struct.pack is always returning a str. And when doing the +=, the Python is trying to decode the str using the UTF-8 encoding so that both are with the same type

The fix was to encode the unicode req into str. So that Python is not trying to decode the result of struct.pack

        if isinstance(req, unicode):
            req = req.encode('UTF-8')
        req += struct.pack(">H", destport)

And this is my gcloud version in case anyone wants to know:

Google Cloud SDK 147.0.0
bq 2.0.24
bq-nix 2.0.24
core 2017.03.13
core-nix 2017.03.13
gcloud 
gcloud-deps 2017.03.13
gcloud-deps-darwin-x86_64 2017.03.13
gsutil 4.22
gsutil-nix 4.22
kubectl 
kubectl-darwin-x86_64 1.5.3
«Newer      Older»

----Comments(1)----
Hamza at 2017-04-29 09:48:
That works ! thank you !
Comment:
Name:

Back to home

Subscribe | Register | Login | N