pytogo / portforward

Kubernetes Port-Forward Go-Edition For Python

Home Page:https://portforward.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use without context manager gives error

nampord opened this issue · comments

commented
  • portforward version: 0.6.1
  • Python version: 3.11.5
  • Operating System: windows 11

Description

port forwarding with a context works well

with portforward.forward(namespace, pod_name,12345, pod_port):
#do work ...
#e.g. working with sqlachemy
engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:12345/mydatabase")
...
However

forwarder = portforward.forward(namespace, pod_name, 12345, pod_port)
engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:12345/mydatabase")
....
forwarder.stop()

does not work
( connection to server at "localhost" (127.0.0.1), port 12345 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections )

According to
https://portforward.readthedocs.io/en/latest/portforward.html#module-portforward
should work as well

Anything I missed ?

Hi @nampord.

you are right. And I have no clue why I wrote it like this in the docs. But the code can be easily changed to make it work

Try this instead

forwarder = portforward.PortForwarder(namespace, pod_name, 12345, pod_port)
forwarder.forward()
engine = create_engine("postgresql+psycopg2://scott:tiger@localhost:12345/mydatabase")
...
forwarder.stop()

I will remove this wrong part of the documentation.

I hope my comment helped you. Else feel free to reopen the issue.

commented