gsutil file download OSError: Permission denied. KiB

Viewed 5183

I am trying to download some samples from Google storage to do a sentiment analysis. I am following the instructions but get an error (I actually added a destination file to their instruction and the error is different):

Error as defined by Google on example: Jorge:python3.7 jbp$ gsutil cp gs://cloud-samples-tests/natural-language/sentiment-samples.tgz CommandException: Wrong number of arguments for "cp" command. Traceback (most recent call last): File "", line 1, in File "/Users/jbp/Python/env/lib/python3.7/google-cloud-sdk/platform/gsutil/gslib/init.py", line 29, in import tempfile File "tempfile.py", line 39, in import functools as _functools File "functools.py", line 8 SyntaxError: Non-ASCII character '\xc5' in file functools.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details Jorges-MBP:python3.7 jbarrigapartarrieu$

Error with destination file: Jorge:python3.7 jbp$ gsutil cp gs://cloud-samples-tests/natural-language/sentiment-samples.tgz /User/jbp/Python Copying gs://cloud-samples-tests/natural-language/sentiment-samples.tgz... OSError: Permission denied. KiB]
Traceback (most recent call last): File "", line 1, in File "/Users/jbarrigapartarrieu/Python/env/lib/python3.7/google-cloud-sdk/platform/gsutil/gslib/init.py", line 29, in import tempfile File "tempfile.py", line 39, in import functools as _functools File "functools.py", line 8 SyntaxError: Non-ASCII character '\xc5' in file functools.py on line 8, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

3 Answers

Adding sudo to the line solved my problem

sudo gsutil cp gs://cloud-samples-tests/natural-language/sentiment-samples.tgz ./

It looks like the user executing the gsutil command doesn't have permission to write to /User/jbp/Python or the path doesn't exist.

On a linux system, you can check the path's permissions and owner(s) using namei:

namei -mo /User/jbp/Python

Alternativelly, try saving the file to your working directory:

 gsutil cp gs://cloud-samples-tests/natural-language/sentiment-samples.tgz ./
Related