Access google storage client using dictionary


I have a service account in a form of dictionary. Below is the service account

service_account = {
  "type": "service_account",
  "project_id": "project_id",
  "private_key_id": "private_key_id",
  "private_key":  "PRIVATE KEY",
  "client_email": "email",
  "client_id": "111111",
  "auth_uri": "",
  "token_uri": "",
  "auth_provider_x509_cert_url": "",
  "client_x509_cert_url": ""

The above details are simulated. I want to access the google storage using the above dictionary but not using ".json" file. Below is the code that I am trying

    from import storage
    storage_client = storage.Client.from_service_account_json(service_account)
    bucket = storage_client.bucket(bucket_name)
    blob = bucket.blob(blob_name)
    file_data = json.loads(blob.download_as_string())

Getting the below error

    storage_client = storage.Client.from_service_account_json(service_account)
  File "/usr/local/lib/python3.9/site-packages/google/cloud/", line 106, in from_service_account_json
    with, "r", encoding="utf-8") as json_fi:
TypeError: expected str, bytes or os.PathLike object, not dict
Asked By: merkle



It looks like this can be done with the
from_service_account_info() method instead of from_service_account_json.

Answered By: somethingsomething