Forums

Script works fine from bash console; "Connection refused" error through Scheduled Tasks

I've had scheduled a task working perfectly well for the past couple weeks. Last night, it just stopped working with this error:

Traceback (most recent call last):
  File "/usr/local/lib/python3.3/dist-packages/mysql/connector/network.py", line 383, in open_connection
    self.sock.connect(sockaddr)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/alexpmil/filename.py", line 62, in <module>
    db, cur = connectDB()
  File "/home/alexpmil/filename.py", line 47, in connectDB
    db = conn.connect(host="mysql.server",user="REDACTED",passwd="REDACTED", database="REDACTED")
  File "/usr/local/lib/python3.3/dist-packages/mysql/connector/__init__.py", line 101, in connect
    return MySQLConnection(*args, **kwargs)
  File "/usr/local/lib/python3.3/dist-packages/mysql/connector/connection.py", line 117, in __init__
    self.connect(**kwargs)
  File "/usr/local/lib/python3.3/dist-packages/mysql/connector/connection.py", line 383, in connect
    self._open_connection()
  File "/usr/local/lib/python3.3/dist-packages/mysql/connector/connection.py", line 346, in _open_connection
    self._socket.open_connection()
  File "/usr/local/lib/python3.3/dist-packages/mysql/connector/network.py", line 386, in open_connection
    errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'mysql.server:3306' (111 Connection refused)

The script works from the bash console (python filename.py), but I'm seeing this error in the scheduled tasks log.

Any help?

Edit: Actually, the script only works from bash if I use python3.3 filename.py, but I get a completely different error if I leave the 3.3 off than the one I'm seeing above. Also, I thought the python version wouldn't be an issue as long I'm including #!/usr/local/bin/python3.3 at the top of my file (which I am).

Followed this answer from a thread that seems to be having the same problem right now. It seems to work for now, but will update with any issues.

Right, if you use the server name alexpmil.mysql.pythonanywhere-services.com then it should be more reliable. We're planning to retire the old mysql.server naming convention soon; the new-style name is still officially in beta, but it looks like it's already much more reliable.

After our system update today, the username-based hostname is now the official way to connect to your MySQL database. The old mysql.server system still works, but is now deprecated.