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:

credentials = service_account.Credentials.from_service_account_info(

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\", line 556, in _run_script
    exec(code, module.__dict__)
  File "C:\Users\s.kian\OneDrive - Intrum Law\Desktop\tt\", 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\", 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\", 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\", 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\", 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\", 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\", 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\", 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.

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.