Remedy for No key could be detected.

Error log

Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.7/site-packages/firebase_admin/credentials.py", line 96, in __init__
    json_data, scopes=_scopes)
  File "/app/.heroku/python/lib/python3.7/site-packages/google/oauth2/service_account.py", line 201, in from_service_account_info
    info, require=["client_email", "token_uri"]
  File "/app/.heroku/python/lib/python3.7/site-packages/google/auth/_service_account_info.py", line 55, in from_dict
    signer = crypt.RSASigner.from_service_account_info(data)
  File "/app/.heroku/python/lib/python3.7/site-packages/google/auth/crypt/base.py", line 114, in from_service_account_info
    info[_JSON_FILE_PRIVATE_KEY], info.get(_JSON_FILE_PRIVATE_KEY_ID)
  File "/app/.heroku/python/lib/python3.7/site-packages/google/auth/crypt/_python_rsa.py", line 171, in from_string
    raise ValueError("No key could be detected.")
ValueError: No key could be detected.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 28, in <module>
    "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-vbo7h%40jun-remind.iam.gserviceaccount.com"
  File "/app/.heroku/python/lib/python3.7/site-packages/firebase_admin/credentials.py", line 99, in __init__
    'Caused by: "{0}"'.format(error))
ValueError: Failed to initialize a certificate credential. Caused by: "No key could be detected."

approach

  1. Change the key of heroku environment variable to uppercase
  2. Convert the line feed code of private_key
os.environ["PRIVATE_KEY"].replace('\\n', '\n')

reference

https://github.com/firebase/firebase-admin-python/issues/188

Recommended Posts

Remedy for No key could be detected.
How to log with python (when No handlers could be found for logger "__main__" appears)