podman-py icon indicating copy to clipboard operation
podman-py copied to clipboard

podman run not working

Open KaiBroeker opened this issue 3 years ago • 4 comments

Hello,

I use the lib version 4.2.0, Python 3.10.4, podman 3.4.4.

If I try to use client.containers.run I get the following error:

>>> import podman
>>> 
>>> client = podman.PodmanClient()
>>> 
>>> client.images.pull("docker.io/library/ubuntu:20.04")
<Image: 'docker.io/library/ubuntu:20.04'>
>>> 
>>> image = client.images.pull("docker.io/library/ubuntu:20.04")
>>> 
>>> client.containers.run(image, ["ls", "/"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kai/.local/lib/python3.10/site-packages/podman/domain/containers_run.py", line 80, in run
    exit_status = container.wait()["StatusCode"]
TypeError: 'int' object is not subscriptable
>>> 

Are I'm doing something wrong or is there a bug?

Thanks for the help Kai

KaiBroeker avatar Aug 25 '22 10:08 KaiBroeker

Same thing with lib version 4.2.0, Python 3.9.7, podman 4.2.0. I tried debugging this for a few hours and found that container.wait() is returning from requests and is valid json, which is a single integer. That line attempts to then treat it as a dictionary and pull the key StatusCode out, which fails in a TypeError. I was never able to get past this either.

>>> import json; json.loads(json.dumps(0))
0
>>>podman --version
podman version 4.2.0

>>>python -c "import podman; print(podman.__version__)"
4.2.0

import podman
uri = "http://127.0.0.1:8090"
client = podman.PodmanClient(base_url=uri)
client.images.pull("docker.io/library/ubuntu:20.04")
image = client.images.pull("docker.io/library/ubuntu:20.04")
client.containers.run(image, ["ls", "/"])        

>>>python
Python 3.9.7 (default, Sep 16 2021, 13:09:58)
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import podman
>>> uri = "http://127.0.0.1:8090"
>>> client = podman.PodmanClient(base_url=uri)
>>> client.images.pull("docker.io/library/ubuntu:20.04")
<Image: 'docker.io/library/ubuntu:20.04'>
>>> image = client.images.pull("docker.io/library/ubuntu:20.04")
>>> client.containers.run(image, ["ls", "/"])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "****/lib/python3.9/site-packages/podman/domain/containers_run.py", line 80, in run
    exit_status = container.wait()["StatusCode"]
TypeError: 'int' object is not subscriptable
>>>
        

ericpershey avatar Aug 30 '22 21:08 ericpershey

@cdoern @mwhahaha PTAL

rhatdan avatar Aug 31 '22 12:08 rhatdan

this is not new for 4.2 or the previous version, unless something changes with the container wait method in podman. I will look at this.

cdoern avatar Sep 05 '22 18:09 cdoern

It seems the wait on libpod returns a single integer rather than json with StatusCode. This may be all because I am using http://127.0.0.1:8090. https://docs.podman.io/en/latest/_static/api.html#tag/containers/operation/ContainerWaitLibpod vs https://docs.docker.com/engine/api/v1.40/#tag/Container/operation/ContainerWait

Example:

curl -X POST http://localhost:8090/v4.2.0/libpod/containers/220b34da1552337c7bcb31a422f51407ce3bdb0748884d6f5f5c5f84e4f5efe5/wait 0

curl -X POST http://localhost:8090/v1.41/containers/220b34da1552337c7bcb31a422f51407ce3bdb0748884d6f5f5c5f84e4f5efe5/wait {"StatusCode":0,"Error":null}

Inside api/client.py you can see the compatible_prefix, but if you specify that in the kwargs, it blows up if you use HTTPAdapter, because it doesn't allow the compatible_version kwarg. It then uses self.path_prefix and that's where it gets libpod from. I thought that might be a way to get this to work, but it did not.

       self.path_prefix = f"/v{self.version}/libpod/"
        self.compatible_version = kwargs.get("compatible_version", api.COMPATIBLE_VERSION)
        self.compatible_prefix = f"/v{self.compatible_version}/"

Below are some of the requests coming from podman-py.

127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "POST /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/start HTTP/1.1" 204 0 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"
127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "POST /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/wait?condition=running&condition=exited HTTP/1.1" 200 2 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"
127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "GET /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/json HTTP/1.1" 200 4826 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"
127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "GET /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/logs?follow=True&stderr=False&stdout=True HTTP/1.1" 200 21 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"
127.0.0.1 - - [08/Sep/2022:17:02:16 -0500] "POST /v4.2.0/libpod/containers/3605caa5d93fe09515c5add54ee284df75e362e9286e2999f3863f1338ce9081/wait HTTP/1.1" 200 2 "" "PodmanPy/4.2.0 (API v4.2.0; Compatible v1.40)"

ericpershey avatar Sep 08 '22 22:09 ericpershey

This remains broken on master as of today.

jonathanunderwood avatar Jan 13 '23 17:01 jonathanunderwood