在python里连接mysql报错

在python里连接mysql报错pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '172.0.0.0' (timed out)")

                      import pymysql


                      connect = pymysql.connect(host='172.0.0.0',  
                      port=3306,                              
                      user='root',
                      password='1234',
                      db='3306',
                      charset='utf8'
                      )
                      cur = connect.cursor()
                      print(cur)

报错代码:

img

搜了一下,关了防火墙,启动了mysql服务,cmd进入mysql都可以,不知道为什么pycharm连接不上mysql
请大家帮我看看为啥连接不上,不懂怎么解决!https://img-mid.csdnimg.cn/release/static/image/mid/ask/510994837356153.png "#left")

错误一:During handling of the above exception, another exception occurred:在处理上述异常期间,发生了另一个异常。

造成这个问题的原因五花八门,属于疑难杂症之一。

错误二:TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

对于错误二如果想不处理,可以直接在request.get()函数中加个timeout参数:

eq = requests.get(url, headers=headers, proxies=proxies, timeout=5)

timeout 是用作设置响应时间(单位:秒)的,可以设置一个float或者一个tuple参数,响应时间分为连接时间和读取时间,timeout(3,7)表示连接时间3秒,响应时间7秒。

解决:代理ip使用的协议不正常,使用正确的协议

proxies = {'http' : ip}

proxies = {'https' : ip}

http和https是不能写错的

是我不够细心,代码输错了没连接上,没什么其他问题,host="127.0.0.1",db=数据库名称,port可以省略