Incorrect padding

I am trying to connect streamlit app to the google sheets as guided by the streamlit community. after running the following part of the code:

scope=[“https://www.googleapis.com/auth/drive”,
https://www.googleapis.com/auth/spreadsheets”]
credentials = service_account.Credentials.from_service_account_info(
st.secrets[“gcp_service_account”],
scopes=scope,
)

I face the following error.

2022-08-22 16:03:54.453 Uncaught app exception
Traceback (most recent call last):
  File "C:\Users\s.kian\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 556, in _run_script
    exec(code, module.__dict__)
  File "C:\Users\s.kian\OneDrive - Intrum Law\Desktop\tt\gsh.py", line 11, in <module>
    credentials = service_account.Credentials.from_service_account_info(
  File "C:\Users\s.kian\AppData\Local\Programs\Python\Python310\lib\site-packages\google\oauth2\service_account.py", line 221, in from_service_account_info
    signer = _service_account_info.from_dict(
  File "C:\Users\s.kian\AppData\Local\Programs\Python\Python310\lib\site-packages\google\auth\_service_account_info.py", line 58, in from_dict
    signer = crypt.RSASigner.from_service_account_info(data)
  File "C:\Users\s.kian\AppData\Local\Programs\Python\Python310\lib\site-packages\google\auth\crypt\base.py", line 113, in from_service_account_info
    return cls.from_string(
  File "C:\Users\s.kian\AppData\Local\Programs\Python\Python310\lib\site-packages\google\auth\crypt\_python_rsa.py", line 154, in from_string
    marker_id, key_bytes = pem.readPemBlocksFromFile(
  File "C:\Users\s.kian\AppData\Local\Programs\Python\Python310\lib\site-packages\pyasn1_modules\pem.py", line 44, in readPemBlocksFromFile
    substrate = ''.encode().join([base64.b64decode(x.encode()) for x in certLines])
  File "C:\Users\s.kian\AppData\Local\Programs\Python\Python310\lib\site-packages\pyasn1_modules\pem.py", line 44, in <listcomp>
    substrate = ''.encode().join([base64.b64decode(x.encode()) for x in certLines])
  File "C:\Users\s.kian\AppData\Local\Programs\Python\Python310\lib\base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

I searched a lot in the internet, not found anything. I am in urgent need of your kind responses.
Thanks

My guess is that there’s some formatting error in your “gcp_service_acount” entry in secrets.toml. That can be tricky to get right, because it includes an embedded private key with \n characters in it.

Could you double check and make sure your toml is formatted correctly? This is what the entry should look like:

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.