Hi all, I am running into a similar issue. I had tried to connect to my database on python anywhere directly from my code on my local computer. After reading previous comments, I decided to use the SSHTunnel method. Here is my code for setting everything up.
host = 'xxx.mysql.pythonanywhere-services.com'
user = 'xxx'
password = 'xxx'
db = 'xxx$zipcode_census'
#normally local code cannot interact with pythonanywhere database servers
#must use sshtunnel to set up an external connection
) as server:
connection = mysql.connector.connect(
cursor = connection.cursor()
However, when I run the code I receive the following error:
2018-06-01 17:26:00,573| ERROR | Could not connect to gateway ssh.pythonanywhere.com:22 : 61
Traceback (most recent call last):
File "US_zipcode_cleaner.py", line 43, in <module>
File "US_zipcode_cleaner.py", line 22, in data_cleaner
File "/usr/local/lib/python3.6/site-packages/sshtunnel.py", line 1486, in __enter__
File "/usr/local/lib/python3.6/site-packages/sshtunnel.py", line 1228, in start
reason='Could not establish session to SSH gateway')
File "/usr/local/lib/python3.6/site-packages/sshtunnel.py", line 1038, in _raise
sshtunnel.BaseSSHTunnelForwarderError: Could not establish session to SSH gateway
Any help would be greatly appreciated!