googledatalab / datalab

Interactive tools and developer experiences for Big Data on Google Cloud Platform.
Apache License 2.0
974 stars 249 forks source link

Cannot display subprocess error, but show TypeError: write() argument must be str, not bytes #2178

Open dwy6626 opened 3 years ago

dwy6626 commented 3 years ago

in #2157, user without compute.instances.list permission run the following command

datalab connect instance-name

will get error:

write() argument must be str, not bytes

When run with --verbosity debug flag, I get errors:

Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/platform/datalab-cli/commands/utils.py", line 304, in describe_instance
    gcloud_compute(args, get_cmd, stdout=stdout, stderr=stderr)
  File "/usr/bin/../lib/google-cloud-sdk/platform/datalab-cli/datalab.py", line 201, in gcloud_compute
    cmd, stdin=stdin, stdout=stdout, stderr=stderr)
  File "/usr/lib/python3.7/subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['gcloud', 'compute', '--verbosity=debug', 'instances', 'describe', '--quiet', '--format', 'json(status,tags.items,metadata.items,disks[].licenses)', 'instance-name']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/google-cloud-sdk/platform/datalab-cli/commands/utils.py", line 304, in describe_instance
    gcloud_compute(args, get_cmd, stdout=stdout, stderr=stderr)
  File "/usr/bin/../lib/google-cloud-sdk/platform/datalab-cli/datalab.py", line 201, in gcloud_compute
    cmd, stdin=stdin, stdout=stdout, stderr=stderr)
  File "/usr/lib/python3.7/subprocess.py", line 347, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['gcloud', 'compute', '--verbosity=debug', 'instances', 'describe', '--quiet', '--zone', 'us-west1-a', '--format', 'json(status,tags.items,metadata.items,disks[].licenses)', 'instance-name']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/../lib/google-cloud-sdk/platform/datalab-cli/datalab.py", line 434, in run
    sdk_version=sdk_version, datalab_version=datalab_version)
  File "/usr/lib/google-cloud-sdk/platform/datalab-cli/commands/connect.py", line 382, in run
    args, gcloud_compute, instance)
  File "/usr/lib/google-cloud-sdk/platform/datalab-cli/commands/utils.py", line 322, in describe_instance
    args, gcloud_compute, instance)
  File "/usr/lib/google-cloud-sdk/platform/datalab-cli/commands/utils.py", line 316, in describe_instance
    sys.stderr.write(stderr.read())
TypeError: write() argument must be str, not bytes
write() argument must be str, not bytes

Environment:

GCP cloud shell with python 3.7.3