HandlerSSHTunnelForwarderError with SSHTunnelForwarder
Question: I am trying to connect to my remote postgres db as follows:

    
    
    from sshtunnel import SSHTunnelForwarder #Run pip install sshtunnel
    from sqlalchemy.orm import sessionmaker #Run pip install sqlalchemy
    
    with SSHTunnelForwarder(
        ('10.160.1.24', 22), #Remote server IP and SSH port
        ssh_username = "<usr>",
        ssh_password = "<pwd>",
        remote_bind_address=('10.160.1.24', 5432),
        local_bind_address=('127.0.0.1', 3334)
        ) as server:
    
        server.start() #start ssh sever
        print 'Server connected via SSH'
    
        #connect to PostgreSQL
        local_port = str(server.local_bind_port)
        engine = create_engine('postgresql://<db_user>:<db_pwd>@127.0.0.1:' + local_port +'/<db_name>')
    
        Session = sessionmaker(bind=engine)
        session = Session()
    
        print 'Database session created'
    
        #test data retrieval
        test = session.execute("SELECT * FROM <table_name>")
    

This is the output that I see:

    
    
    File "/Library/Python/2.7/site-packages/sshtunnel.py", line 299, in handle
    raise HandlerSSHTunnelForwarderError(msg)
    HandlerSSHTunnelForwarderError: In #1 <-- ('127.0.0.1', 54265) to ('10.160.1.24', 5432) failed: ChannelException(2, 'Connect failed')
    

Any idea what I am doing wrong? I am able to connect to the postgresdb by
running the command `ssh -L 3334:localhost:5432 Administrator@10.160.1.24` in
a seperate terminal and then connecting to the db at localhost:3334.


Answer: Found my mistake!

`remote_bind_address=('10.160.1.24', 5432)` should be
`remote_bind_address=('127.0.0.1', 5432),`

