Search code examples
pythonmysqlpythonanywhere

Secsh channel 0 open FAILED: open failed: Administratively prohibited pythonanywhere


I am trying to connect to MySQL database that is hosted on pythonanywhere.com but it is bringing below error

2021-10-19 13:02:38,943| ERROR   | Secsh channel 0 open FAILED: open failed: Administratively prohibited
2021-10-19 13:02:38,943| ERROR   | Could not establish connection from local ('127.0.0.1', 62213) to remote ('lewisMachilika.mysql.pythonanywhere-services.com', 3306) side of the tunnel: open new channel ssh error: ChannelException(1, 'Administratively prohibited')

my file is

import MySQLdb
import sshtunnel

sshtunnel.SSH_TIMEOUT = 5.0
sshtunnel.TUNNEL_TIMEOUT = 5.0

with sshtunnel.SSHTunnelForwarder(
    ('ssh.pythonanywhere.com'),
    ssh_username='xxxxx', ssh_password='xxxxxx',
    remote_bind_address=('xxxxxxxx', 3306)
) as tunnel:
    connection = MySQLdb.connect(
        user='xxxxxx',
        passwd='xxxxx',
        host='127.0.0.1', port=tunnel.local_bind_port,
        db='xxxxxx',
    )
    # Do stuff
    connection.close()

Solution

  • This needs a paid account to use SSH (including SSH tunnelling) on PythonAnywhere.