Hello, I have a paid plan and en error. Maybe you can give me an idea whats going wrong.
from flask import Flask
import MySQLdb
import sshtunnel
# Set SSH and Tunnel timeouts
sshtunnel.SSH_TIMEOUT = 2.0
sshtunnel.TUNNEL_TIMEOUT = 2.0
app = Flask(__name__)
with sshtunnel.SSHTunnelForwarder(
('ssh.eu.pythonanywhere.com'),
ssh_username='pythonanywhereusername',
ssh_password='eu.pythonanywherepassword',
remote_bind_address=('xxxx.mysql.eu.pythonanywhere-services.com', 3306),
# debug_level='TRACE'
) as tunnel:
print("SSH tunnel established.")
try:
conn = MySQLdb.connect(
user='pythonanywhereusername',
passwd='MySQLpassword',
host = "127.0.0.1",
port=tunnel.local_bind_port,
db='username$default'
)
print("Database connection established.")
except (sshtunnel.BaseSSHTunnelForwarderError, MySQLdb.Error) as e:
print(f"Failed to connect: {type(e).__name__}, {str(e)}")
except Exception as e:
print(f"An unexpected error occurred: {type(e).__name__}, {str(e)}")
if __name__ == '__main__':
app.run(debug=True)
Gives error:
SSH tunnel established.
Failed to connect: OperationalError, (2013, "Lost connection to server at 'handshake: reading initial
communication packet', system error: 0")
2023-09-10 07:42:36,607| ERROR | Secsh channel 0 open FAILED: open failed: Administratively prohibited
2023-09-10 07:42:36,607| ERROR | Could not establish connection from local ('127.0.0.1', 57088) to remote
('xxxx.mysql.eu.pythonanywhere-services.com', 3306) side of the tunnel: open new channel ssh error:
ChannelException(1, 'Administratively prohibited')
* Serving Flask app 'squirrel_test_1'
* Debug mode: on
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI
server instead.
* Running on http://127.0.0.1:5000
So the Tunnel seems to work. But it goes wrrong in the "handshake"
Does anyone recognise this problem? I am happy with any help. Greetings Yves