MySQL Forums
Forum List  »  Connector/Python

ConnectionRefusedError: WinError 10061 Python
Posted by: Sam Slusky
Date: May 26, 2020 04:53AM

Good Morning,

Set MySQL up on my computer with seemingly no problem, Created a database "servers" and connected to it on 127.0.0.1:3306. According to the Server Status pane, the server is running. According to the PHP code and through testing the connection in the Connect to Database view I'm reasonably confident that the following connection information is accurate (with the password not being included

$host="127.0.0.1";
$port=3306;
$socket="";
$user="slusks";
$password="";
$dbname="servers";

That being said, when I try and connect via the following python script, I get an error:

##Python 3.7
import mysql.connector
from mysql.connector import errorcode

try:
mydb = mysql.connector.connect(
host="127.0.0.1",
port ="3306",
user="slusks",
password="[REMOVED]",
dbname="servers"
auth_plugin='mysql_native_password'
)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
mydb.close()

print (mydb)


ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

I've tried changing firewall settings, I've tried changing python versions and i've removed and re-installed mysql-connector. I've seen variations of this question pop up but nobody seems to have provided an answer, or confirmed the answer works. I'm looking for suggestions/advice on how I might resovle this. I'll post the full traceback below this.

Best regards,
- Sam

Traceback (most recent call last):
File "C:\Python37\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "c:\Users\sam\.vscode\extensions\ms-python.python-2020.5.80290\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher\__main__.py", line 95, in <module>
main()
File "c:\Users\sam\.vscode\extensions\ms-python.python-2020.5.80290\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher\__main__.py", line 51, in main
launcher.connect(host, port)
File "c:\Users\sam\.vscode\extensions\ms-python.python-2020.5.80290\pythonFiles\lib\python\debugpy\wheels\debugpy\launcher/../..\debugpy\launcher\__init__.py", line 34, in connect
sock.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

Options: ReplyQuote


Subject
Written By
Posted
ConnectionRefusedError: WinError 10061 Python
May 26, 2020 04:53AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.