[Python] PyP100 Tapo‑Plug control works with docker run but fails with docker compose run/up...

Discussão em 'Python' iniciado por Stack, Julho 14, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Python application using PyP100 to control a TP‑Link Tapo smart plug. Specifically I'm using almottier's fork. I need to use it in a docker container.

    When I build and launch my Docker image directly with docker run, everything works: the plug’s handshake succeeds, and I can power it on/off. However, when I try to run the same image via Docker Compose—either with docker compose run or docker compose up the handshake fails with:

    Traceback (most recent call last):
    File "/app/src/host_commands.py", line 24, in turn_on
    plug.turnOff()
    File "/usr/local/lib/python3.12/site-packages/PyP100/PyP100.py", line 98, in turnOff
    return self.set_status(False)
    ^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/site-packages/PyP100/PyP100.py", line 92, in set_status
    return self._set_device_info({"device_on": status})
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/site-packages/PyP100/PyP100.py", line 64, in _set_device_info
    return self.request("set_device_info", params)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.12/site-packages/PyP100/PyP100.py", line 46, in request
    self._initialize()
    File "/usr/local/lib/python3.12/site-packages/PyP100/PyP100.py", line 42, in _initialize
    raise Exception("Failed to initialize protocol")
    Exception: Failed to initialize protocol


    This is the docker run command that I use:

    docker run --rm \
    --env-file .env \
    --volume "$(pwd)/logs:/app/logs" \
    --volume "$(pwd)/scripts:/app/scripts" \
    --network host \
    --privileged \
    --cap-add NET_ADMIN \
    --cap-add NET_RAW \
    tapo:1.0


    And this is the docker-compose:

    services:
    tapo-backup:
    image: tapo:1.0
    env_file:
    - .env
    volumes:
    - ./logs:/app/logs
    - ./scripts:/app/scripts
    network_mode: host
    restart: on-failure
    privileged: true
    cap_add:
    - NET_ADMIN
    - NET_RAW


    Just in case this is the .env file:

    # MAC Addresses
    PLUG_MAC=MAC_ADDRESS1
    REMOTE_HOST_MAC=MAC_ADDRESS2

    # TAPO Credentials
    EMAIL=myemail@gmail.com
    PASSWORD=password

    # borgbackup
    BORG_PASSPHRASE=XYZl0ngandsecurepa_55_phrasea&&123
    BORG_REPOS_PATH=/path/to/repos

    # Others
    SSH_USERNAME=username
    SUBNET=192.168.1.0/24
    TZ=Europe/Berlin


    Do you have any idea about this? Thanks in advance

    I was expecting that both docker run and docker compose run/up would provide an identical runtime so that PyP100 would succeed under Compose exactly as it does under docker run.

    Continue reading...

Compartilhe esta Página