Pydrive does not work after deploying my app on Streamlit Cloud

Hello everyone,
I have created an app which takes some info from the user and uploads it to Google Sheets (simple database). I have also added an upload file widget which is supposed to upload a file from the user to drive using the pydrive library. This worked perfectly before deploying the app, but now I am having problems with it. The error I am getting is:

File "/home/appuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script
    exec(code, module.__dict__)
File "/app/testing/project.py", line 409, in <module>
    main()
File "/app/testing/project.py", line 262, in main
    gfile.Upload()
File "/home/appuser/venv/lib/python3.9/site-packages/pydrive/files.py", line 285, in Upload
    self._FilesInsert(param=param)
File "/home/appuser/venv/lib/python3.9/site-packages/pydrive/auth.py", line 57, in _decorated
    self.auth.LocalWebserverAuth()
File "/home/appuser/venv/lib/python3.9/site-packages/pydrive/auth.py", line 115, in _decorated
    code = decoratee(self, *args, **kwargs)
File "/home/appuser/venv/lib/python3.9/site-packages/pydrive/auth.py", line 224, in LocalWebserverAuth
    raise AuthenticationError()```

Code snippet of my code which produces the error:

with NamedTemporaryFile() as f:
                gauth = GoogleAuth()
                #gauth.LocalWebserverAuth()
                drive = GoogleDrive(gauth)
                client_json_path = 'path'    
                GoogleAuth.DEFAULT_SETTINGS['client_config_file'] = client_json_path
                drive_key = st.secrets["drive_key"]
                f.write(cv.getvalue())
                gfile = drive.CreateFile({"parents": [{"id": drive_key}], "title": cv.name})
                st.write(gfile)
                gfile.SetContentFile(f.name)
                gfile.Upload()
                st.write("success")

Thanks in advance for any help

pydrive.auth.AuthenticationError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).

I forgot to add the name of the error.

Hi, there seems to be an issue with authentication, and from your code there is a reference to st.secrets, have you defined β€œdrive_key” in the Secrets management on the Streamlit Community Cloud?

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