แต่ถ้าเป็นลิงค์ localhost หรือลิงค์ที่มีการแก้ไข domain name อย่าง www.google2.com , www.goo2gle.com ก็จะมีปัญหา raise URLError(err) ครับ
โค้ดที่ใช้ตรวจสอบลิงค์
โค้ด: เลือกทั้งหมด
try:
response = urllib.request.urlopen(line)
if response.getcode() == 200:
save_link.append(str(n)+" "+"That link is ok:"+line)
check.append("Y")
print("""This link is ok:{} Time_test :{}{}{}{}{} """.format(line, time_hr,":",time_min,":",time_sec))
else:
print('The response code was not 200, but: {}'.format(response.get_code()))
except urllib.error.HTTPError as e:
print('''This link is error occurred:{}
The response code was {}
Time_test :{}{}{}{}{}'''.format(line,e.getcode(), time_hr,":",time_min,":",time_sec))
save_link.append(str(n)+" "+"That link is error occurred:" + line)
check.append("N")
error ลิงค์ที่มีการแก้ไข domain name ตัวอย่างลิงค์ :raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 111] Connection refused>
1. https://www.google4.com/
2. https://www.goo5gle.com/raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)>
ช่วยแนะนำวิธีการแก้ error หน่อยครับraise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>
ตอนนี้ผมกำลังลองศึกษา module validators อยู่ครับ ไม่ทราบว่าสามารถเอาไปใช้ได้มั้ยครับ