Forums

Issue with SSH Tunneling to PostgreSQL Database on PythonAnywhere

Hello Please i am facing this issue when connecting postgres outside pythonanywhere can anyone help please

INFO:paramiko.transport:Authentication (password) successful! DEBUG:paramiko.transport:[chan 0] Max packet in: 32768 bytes DEBUG:paramiko.transport:Received global request "hostkeys-00@openssh.com" DEBUG:paramiko.transport:Rejecting "hostkeys-00@openssh.com" global request from server. 2023-10-26 13:32:26,456| ERROR | Secsh channel 0 open FAILED: open failed: Administratively prohibited ERROR:paramiko.transport:Secsh channel 0 open FAILED: open failed: Administratively prohibited 2023-10-26 13:32:26,456| ERROR | Could not establish connection from local ('127.0.0.1', 5500) to remote ('mydb.postgres.pythonanywhere-services.com', 13428) side of the tunnel: open new channel ssh error: ChannelException(1, 'Administratively prohibited') ERROR:sshtunnel.SSHTunnelForwarder:Could not establish connection from local ('127.0.0.1', 5500) to remote ('mydb.postgres.pythonanywhere-services.com', 13428) side of the tunnel: open new channel ssh error: ChannelException(1, 'Administratively prohibited') DEBUG:paramiko.transport:EOF in transport thread Traceback (most recent call last): File "\vue\db.py", line 22, in <module> connection = psycopg2.connect( ^^^^^^^^^^^^^^^^^ File "C:\Python311\Lib\site-packages\psycopg2__init__.py", line 122, in connect conn = _connect(dsn, connection_factory=connection_factory, **kwasync) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ psycopg2.OperationalError: connection to server at "127.0.0.1", port 5500 failed: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.

That looks like something on your machine, like an anti-virus or firewall is preventing the SSH tunnel from connecting.

I try in 2 different PC MacBook and Windows but still facing same issue I think the restriction is from Pythonanyway

I also try it in multiple cloud terminals such as AWS and Google Cloud Console Terminals but still facing same error after successfully logging then it will automatically close the connection which this definitely shows me that there must be a restriction in my Pythonanywhere I can’t login even inside Pythonanywhere terminal please you guys should help me to resolve this on time please

By looking at our logs, I see you're trying to SSH using tradebotsnip username, as our servers use Linux OS, filenames are case sensitive, so some operations needed to perform your connection fail. Try using Tradebotsnip instead and see if that helps.

Thank you i successful logging but still facing my main problem which is the log below, Database host and port are not accessible in anywhere. i want to query and send some informations from my database to my PC localhost i create flask app in both pythonanywhere and my localhost but none of them works and all the error i am getting seems to be coming from the Database host and port i try to open the host in my browser is not opening i try to add the port to the host but still not works. please i need solution to this

OperationalError psycopg2.OperationalError: connection to server at "myhost-1198.postgres.pythonanywhere-services.com" (10.0.0.48), port 21344 failed: Connection timed out (0x0000274C/10060) Is the server running on that host and accepting TCP/IP connections?

Please can you reply this on time I am just stick there can’t do anything just waiting for your respond

That looks like you are still trying to connect directly to the database. You can't do that. You need to connect to the local end of the SSH tunnel. See https://help.pythonanywhere.com/pages/AccessingPostgresFromOutsidePythonAnywhere/ and make sure that you read the instructions.

Thanks it works

Glad that worked