Skip to content

Initial port check fails with "object is not subscriptable" #157

Closed

Description

@ulsa

The test worked yesterday. However, when I run the test first thing in the morning, I get this:

Pulling image google/cloud-sdk:latest
Container started: 3355b174d1
ERROR
...
  File ".../lib/python3.7/site-packages/testcontainers/core/container.py", line 100, in get_exposed_port
    mapped_port = self.get_docker_client().port(self._container.id, port)
  File ".../lib/python3.7/site-packages/testcontainers/core/docker_client.py", line 44, in port
    return self.client.api.port(container_id, port)[0]["HostPort"]
TypeError: 'NoneType' object is not subscriptable

However, if I run it again right away, it works. It looks like a timing issue related to Docker startup or something like that. Anything that can be done about this in docker_client.py? Like a None-check and a backoff/retry?

Here is the logging output:

-------------------- >> begin captured logging << --------------------
testcontainers.core.container: INFO: Pulling image google/cloud-sdk:latest
urllib3.connectionpool: DEBUG: http://localhost:None "POST /v1.41/containers/create HTTP/1.1" 201 None
urllib3.connectionpool: DEBUG: http://localhost:None "GET /v1.41/containers/3355b174d177ea9f18decf6d8f4faf58e67a3c730ab91c115286c51652f77570/json HTTP/1.1" 200 None
urllib3.connectionpool: DEBUG: http://localhost:None "POST /v1.41/containers/3355b174d177ea9f18decf6d8f4faf58e67a3c730ab91c115286c51652f77570/start HTTP/1.1" 204 0
testcontainers.core.container: INFO: Container started: 3355b174d1
urllib3.connectionpool: DEBUG: http://localhost:None "GET /v1.41/containers/3355b174d177ea9f18decf6d8f4faf58e67a3c730ab91c115286c51652f77570/json HTTP/1.1" 200 None
--------------------- >> end captured logging << ---------------------

Docker version 20.10.8.

Activity

  1. yakimka commented on Mar 26, 2022

    @yakimka
    Contributor

    I am closing this issue. However, if this problem is still relevant, please open it again, but provide an example to reproduce the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions