Repository: docker/docker-py

Issue:
Containers stats is broken in Docker-py 6.1.0 
Look like Docker-Py breaks the API to retrieve stats from containers. 

With Docker 6.0.1 (on Ubuntu 22.04):

```
>>> import docker
>>> c = docker..from_env()
>>> for i in c.containers.list():
...     i.stats(decode=True)
... 
<generator object APIClient._stream_helper at 0x7f236f354eb0>
```

With Docker 6.1.0:

```
>>> import docker
>>> c = docker..from_env()
>>> for i in c.containers.list():
...     i.stats(decode=True)
... 
Never return anything...
```

Additional information:

```
$ cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.2 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

$ docker version
Client: Docker Engine - Community
 Version:           23.0.1
 API version:       1.42
 Go version:        go1.19.5
 Git commit:        a5ee5b1
 Built:             Thu Feb  9 19:46:56 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.1
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.5
  Git commit:       bc3805a
  Built:            Thu Feb  9 19:46:56 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.19
  GitCommit:        1e1ea6e986c6c86565bc33d52e34b81b3e2bc71f
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
```

Source: https://github.com/nicolargo/glances/issues/2366

Discussion:
thaJeztah: @milas ptal 

Patch:
diff --git a/docker/api/container.py b/docker/api/container.py
index fef76030..40607e79 100644
--- a/docker/api/container.py
+++ b/docker/api/container.py
@@ -1164,8 +1164,9 @@ class ContainerApiMixin:
                     'one_shot is only available in conjunction with '
                     'stream=False'
                 )
-            return self._stream_helper(self._get(url, params=params),
-                                       decode=decode)
+            return self._stream_helper(
+                self._get(url, stream=True, params=params), decode=decode
+            )
         else:
             if decode:
                 raise errors.InvalidArgument(


Test patch:
diff --git a/tests/unit/api_container_test.py b/tests/unit/api_container_test.py
index c605da37..c4e2250b 100644
--- a/tests/unit/api_container_test.py
+++ b/tests/unit/api_container_test.py
@@ -1528,10 +1528,21 @@ class ContainerTest(BaseAPIClientTest):
         fake_request.assert_called_with(
             'GET',
             url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/stats',
+            stream=True,
             timeout=60,
             params={'stream': True}
         )
 
+    def test_container_stats_without_streaming(self):
+        self.client.stats(fake_api.FAKE_CONTAINER_ID, stream=False)
+
+        fake_request.assert_called_with(
+            'GET',
+            url_prefix + 'containers/' + fake_api.FAKE_CONTAINER_ID + '/stats',
+            timeout=60,
+            params={'stream': False}
+        )
+
     def test_container_stats_with_one_shot(self):
         self.client.stats(
             fake_api.FAKE_CONTAINER_ID, stream=False, one_shot=True)