My app connects to mysql directly in addition to django abstraction. "all of the sudden", one of my scheduled task scripts began throwing this error for my connection:
It works just fine on my computer, only gives this traceback on pythonanywhere when run through the scheduler
Traceback (most recent call last): File "/home/NickStefan/swimsetswebsite/swimsetswebsite/swimsetswebsite/swimsets/swimscript/dailyemail.py", line 215, in <module> con = mdb.connect('localhost','nick','dini','mydb') File "/usr/local/lib/python2.7/dist-packages/MySQLdb/init.py", line 81, in Connect return Connection(args, kwargs) File "/usr/local/lib/python2.7/dist-packages/MySQLdb/connections.py", line 187, in init super(Connection, self).init(args, **kwargs2) _mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
2014-05-27 16:52:17 -- Completed task, took 3.00 seconds, return code was 1.
I use these EXACT same parameters both in the working part of my web app and in this scheduled script dailyemail.py
# connect to the database
try:
# my pythonanywhere.
con = mdb.connect('mysql.server','NickStefan','--hidden-for-this-post--','NickStefan$swimsolodb',
use_unicode=True, charset='utf8')
except:
# my local dev database
con = mdb.connect('localhost','nick','----','mydb')
Here is the working part of my webapp that connects just fine:
# connect to the database and run SQL.
# try server, if fail, do local
try:
con = mdb.connect('mysql.server','NickStefan','--hidden--forthispost---','NickStefan$swimsolodb',
use_unicode=True, charset='utf8')
except:
con = mdb.connect('localhost','nick','----','mydb')
cur = con.cursor(mdb.cursors.DictCursor)
Any idea what's up?