[Python] Cache access denied error when chrome driver is used to reach a portal behind a proxy...

Discussão em 'Python' iniciado por Stack, Maio 6, 2025.

  1. Stack

    Stack Membro Participativo

    I have services running on docker containers: -Python-Behave -Selenium -Chrome driver

    I am trying to run the python container with a proxy. There is some problem when i try to reach the URL over the proxy . But I can curl to the same URL and reach it through curl.

    I will paste my dockerfile and compose file

    `FROM python:3.11

    # --- TEMP: Set proxy for build-time (APT + pip) ---
    ENV http_proxy=${http_proxy}
    ENV https_proxy=${https_proxy}
    ENV no_proxy=127.0.0.1,localhost,selenium-hub,chrome
    ENV PIP_ROOT_USER_ACTION=ignore

    # --- APT proxy config ---
    RUN echo 'Acquire::http::proxy "'$http_proxy'";' > /etc/apt/apt.conf.d/95proxy && \
    echo 'Acquire::https::proxy "'$https_proxy'";' >> /etc/apt/apt.conf.d/95proxy

    # --- Install packages ---
    RUN apt-get update && \
    apt-get install -y sshpass && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

    # --- Create Jenkins-compatible user ---
    RUN groupadd -g 1000 jenkins_slave && \
    useradd -m -r -u 1000 -g jenkins_slave jenkins_slave

    # --- Set up app directory ---
    RUN mkdir -p /app/downloads && \
    chown -R jenkins_slave:jenkins_slave /app
    WORKDIR /app

    # --- Install Python deps ---
    COPY requirements.txt .
    RUN pip install --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

    # --- UNSET proxy to prevent runtime Selenium issues ---
    ENV http_proxy=""
    ENV https_proxy=""
    ENV HTTP_PROXY=""
    ENV HTTPS_PROXY=""

    # --- Add your code ---
    COPY . .

    # --- Switch to non-root user ---
    USER jenkins_slave`


    //docker compose file
    version: "3.7"

    services:
    selenium-hub:
    image: selenium/hub:4.19.1
    container_name: selenium-hub
    ports:
    - "4442:4442"
    - "4443:4443"
    - "4444:4444"
    restart: always

    chrome:
    image: selenium/node-chrome:4.19.1
    container_name: chrome
    depends_on:
    - selenium-hub
    environment:
    - SE_EVENT_BUS_HOST=selenium-hub
    - SE_EVENT_BUS_PUBLISH_PORT=4442
    - SE_EVENT_BUS_SUBSCRIBE_PORT=4443
    - SE_NODE_SESSION_TIMEOUT=60
    - HTTP_PROXY=${http_proxy}
    - HTTPS_PROXY=${https_proxy}
    - NO_PROXY=localhost,127.0.0.1,selenium-hub,chrome
    ports:
    - "5900:5900"
    shm_size: 2gb
    volumes:
    - ./proxy_auth_plugin.zip:/home/seluser/proxy_auth_plugin.zip
    restart: always

    novnc:
    image: dorowu/ubuntu-desktop-lxde-vnc
    container_name: novnc
    ports:
    - "7900:8080"
    environment:
    - VNC_SERVER=chrome:5900
    depends_on:
    - chrome
    restart: always

    python-behave:
    build:
    context: .
    dockerfile: Dockerfile
    container_name: python-behave
    depends_on:
    - selenium-hub
    volumes:
    - .:/app
    - ./downloads:/app/downloads
    working_dir: /app
    environment:
    - HTTP_PROXY=${http_proxy}
    - HTTPS_PROXY=${https_proxy}
    - NO_PROXY=localhost,127.0.0.1,selenium-hub,chrome


    What i tried:

    1. I tried to app chrome proxy extension(zip) file in the python chrome options
    2. Tried to pass the proxy server directly in chrome option argument

    Continue reading...

Compartilhe esta Página