[Python] Error while exporting to Google Sheets 'could not locate runnable browser'

Discussão em 'Python' iniciado por Stack, Março 4, 2025.

  1. Stack

    Stack Membro Participativo

    I am exporting my data in Google Sheets using gspread library for Python. In local everything worked fine, a browser opens for auth and is able to export it. When I deploy it on prod in a Docker container I get the below error:

    error: "could not locate runnable browser"


    A quick search on the internet suggests that it can be due to the browser not opening up when but not able to figure out why.

    The code I wrote is straightforward and comes from their examples only:

    scopes = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive.file"]
    FLOW_PORT = 35669
    def local_server_flow_fixed_port(client_config, scopes):
    return gspread.auth.local_server_flow(
    client_config=client_config, scopes=scopes, port=FLOW_PORT
    )

    def authorise_gsheet():
    gsheet_client = gspread.auth.oauth(
    flow=local_server_flow_fixed_port,
    credentials_filename=Config.GOOGLE_APPLICATION_CREDENTIALS,
    authorized_user_filename=Config.GOOGLE_AUTHORIZED_FILE_NAME,
    )
    return gsheet_client


    Things I tried so far:


    • I checked the GCreds JSON file to confirm it is correct.


    • Proper permissions are allowed in the Google Cloud console application.


    • Checked Gspread library documentation to see if they have production deployment docs.


    • Machines/Docker has ports open and allowed for traffic.


    • The code is from the example doc only so no changes are needed there.


    • Tried to add Chrome installation steps in the Dockerfile and confirmed it is installed in Docker:

      RUN apt-get install -y wget
      RUN wget -q https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
      RUN apt-get install -y ./google-chrome-stable_current_amd64.deb

    Continue reading...

Compartilhe esta Página