Google Assistant - Could not serialize key data

I noticed that I am getting a large number of errors in my log from the google assistant integration. That being said, the integration does appear to be working properly regardless. Is this something to be worried about?

Logger: homeassistant
Source: components/google_assistant/http.py:54
First occurred: 2:19:12 AM (1 occurrences)
Last logged: 2:19:12 AM

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/jwt/algorithms.py", line 205, in prepare_key
    key = load_pem_private_key(key, password=None, backend=default_backend())
  File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/base.py", line 18, in load_pem_private_key
    return backend.load_pem_private_key(data, password)
  File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1243, in load_pem_private_key
    return self._load_key(
  File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1472, in _load_key
    self._handle_key_loading_error()
  File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1526, in _handle_key_loading_error
    raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/report_state.py", line 80, in inital_report
    await google_config.async_report_state_all({"devices": {"states": entities}})
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/helpers.py", line 172, in async_report_state_all
    await gather(*jobs)
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/http.py", line 204, in async_report_state
    await self.async_call_homegraph_api(REPORT_STATE_BASE_URL, data)
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/http.py", line 179, in async_call_homegraph_api
    await self._async_update_token()
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/http.py", line 153, in _async_update_token
    _get_homegraph_jwt(
  File "/usr/src/homeassistant/homeassistant/components/google_assistant/http.py", line 54, in _get_homegraph_jwt
    return jwt.encode(jwt_raw, key, algorithm="RS256").decode("utf-8")
  File "/usr/local/lib/python3.8/site-packages/jwt/api_jwt.py", line 64, in encode
    return super(PyJWT, self).encode(
  File "/usr/local/lib/python3.8/site-packages/jwt/api_jws.py", line 113, in encode
    key = alg_obj.prepare_key(key)
  File "/usr/local/lib/python3.8/site-packages/jwt/algorithms.py", line 207, in prepare_key
    key = load_pem_public_key(key, backend=default_backend())
  File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/primitives/serialization/base.py", line 23, in load_pem_public_key
    return backend.load_pem_public_key(data)
  File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1273, in load_pem_public_key
    self._handle_key_loading_error()
  File "/usr/local/lib/python3.8/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 1526, in _handle_key_loading_error
    raise ValueError("Could not deserialize key data.")
ValueError: Could not deserialize key data.

I am also having this error. Did you resolve it?

1 Like

Same for me.
No help so far.

I figured out I had my Google Client Key referenced incorrectly. Once I fixed the configuration it worked.

But my key is correct and integration is working.
I only get this error on restart.

What was wrong in your key format?

OK, I solved it.
in configuration I included Key json file instead of values.
service_account: !include SERVICE_ACCOUNT.JSON
SERVICE_ACCOUNT.JSON is downloaded json file from Service Account Key creation.