简体   繁体   中英

Using a service account and JSON key which is sent to you to upload data into google cloud storage

I wrote a python script that uploads files from a local folder into Google cloud storage.

I also created a service account with sufficient permission and tested it on my computer using that service account JSON key and it worked.

Now I send the code and JSON key to someone else to run but the authentication fails on her side.

Are we missing any authentication through GCP UI?

def config_gcloud():
    subprocess.run(
        [
            shutil.which("gcloud"),
            "auth",
            "activate-service-account",
            "--key-file",
            CREDENTIALS_LOCATION,
        ]
    )
    storage_client = storage.Client.from_service_account_json(CREDENTIALS_LOCATION)
    return storage_client


def file_upload(bucket, source, destination):
    storage_client = config_gcloud()
    ...

The error happens in the config_cloud and it says it is expecting str, path, ... but gets NonType. As I said, the code is fine and works on my computer. How anotehr person can use it using JSON key which I sent her?She stored Json locally and path to Json is in the code.

CREDENTIALS_LOCATION is None instead of the correct path, hence it complaining about it being NoneType instead of str|Path.

Also you don't need that gcloud call, that would only matter for gcloud/gsutil commands, not python client stuff.

And please post the actual stacktrace of the error next time, not just a misspelled interpretation of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM