Devdit
 

TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time Python คือ วิธีแก้ไข

1.3K

ภาษา Python รันโปรแกรมเชื่อมต่อญานข้อมูล MySQL แล้วขึ้น Error ว่า TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond แบบนี้แก้ไขอย่างไร

import mysql.connector
cnx = mysql.connector.connect(user='root', password='', host='192.168.1.1', database='db_example', port=3306)

 

วิธีแก้ไข

ปัญหานี้เกิดขึ้นได้หลายสาเหตุ โดยขอแนะนำวิธ๊แก้ไขดังนี้

1. กรณีถ้าโปรแกรม MySQL ติดตั้งเครื่องเดียวกับโค้ด Python ที่รันให้แก้ไข host='192.168.1.1' เป็น host='127.0.0.1'

2. ตรวจสอบว่า Service MySQL ทำงานหรือไม่ (สถานะ Start) หากไม่ทำงานให้ Start Service MySQL ขึ้นมา

แก้ไข 2 ปีที่แล้ว
ชอบ
ลิ้งก์
แชร์
Devdit มีช่อง YouTube แล้ว
เราสร้างวิดีโอเกี่ยวกับเทคโนโลยี ทำตามง่ายๆ