ติดปัญหา check status code of url(ที่มีภาษาไทย) แล้วแจ้ง 403 ครับ

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น ภาษา Java ภาษา Python

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
chakirin.bfds
PHP Super Hero Member
PHP Super Hero Member
โพสต์: 783
ลงทะเบียนเมื่อ: 22/12/2020 10:19 am

ติดปัญหา check status code of url(ที่มีภาษาไทย) แล้วแจ้ง 403 ครับ

โพสต์ที่ยังไม่ได้อ่าน โดย chakirin.bfds »

ได้เขียน script python ในการ monitor website ครับ
ถ้าตรวจเว็บ url ภาษา อังกฤษ จะไม่มีปัญหาครับ แต่ถ้าตรวจ url ที่เป็นภาษาไทย
โปรแกรมจะเเจ้ง error status 403 ครับ ทั้งๆที่สามารถเข้า url ได้ปกติครับ

code ที่ใช้เช็คครับ

โค้ด: เลือกทั้งหมด

#!/usr/bin/python
# -*- coding: utf-8 -*-
#method1
import requests
from requests.exceptions import HTTPError

#method2
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError

import configparser
import time
import email
import smtplib


con = None
config = configparser.ConfigParser()
config.read('admin.conf')

SMTP=config['options']['SMTP']
ports=config['options']['ports']
user = config['options']['user']
password = config['options']['password']
sender = config['options']['sender']
recipient = config['options']['recipient_email']


r_link= open('check_link.txt',"r")
plt = open("plateformEmail.txt")
plt = plt.read()

save_link = []
check = []



n = 0
print("Start_test:", s_t)
for line in r_link:
    print("link:",n)
    n += 1
    line=line.lstrip()


    try:
        response = urlopen(line)

    except HTTPError as e:
        print('The server couldn\'t fulfill the request.',line)
        print('Error code: ', e.code)
        e.code=str(e.code)
        save_link.append(str(n)+" "+'The server couldn\'t fulfill the request '+'('+e.code+')'+' :'+line)
        check.append("N")
    except URLError as e:
        print('We failed to reach a server.',line)
        print('Reason: ', e.reason)
        save_link.append(str(n) + " " + 'We failed to reach a server. :' + line)
        check.append("N")
    else:
        print('Website is working fine',line)
        save_link.append(str(n) + " " + 'Website is working fine. :' + line)
        check.append("Y")
linkตัวอย่าง ที่มีปัญหาในการตรวจสอบ
1 https://www.mindphp.com/%E0%B8%9A%E0%B8 ... nants.html


2 https://www.mindphp.com/%E0%B8%9A%E0%B8 ... nants.html


ซึ่งเมื่อนำลิงค์ไป monitor โปรแกรม แจ้งมาว่า error code 403 ครับ
link: 0
The server couldn't fulfill the request. https://www.ideagital.com/savepong/%E0% ... 4-pomodoro

Error code: 403
link: 1
The server couldn't fulfill the request. https://thaihealthlifestyle.com/article ... %E0%B8%99/
Error code: 403
ไม่ทราบว่าเกิดความผิดพลาดจากอะไรครับ
แก้ไขล่าสุดโดย chakirin.bfds เมื่อ 28/01/2021 8:38 pm, แก้ไขไปแล้ว 4 ครั้ง.
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41232
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

Re: ติดปัญหา check status code of url(ที่มีภาษาไทย) แล้วแจ้ง 403 ครับ

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

ตัวอย่าง URL ที่ Browser อ่านออก
https://www.mindphp.com/%E0%B8%9A%E0%B8 ... nants.html
ของ URL นี้
https://www.mindphp.com/บทความ/31-ความร ... nants.html

โดยการ parse String ของ URL
ตัวอย่าง

โค้ด: เลือกทั้งหมด

 import urllib.parse
query = 'Hellö Wörld@Python'
urllib.parse.quote(query)
'Hell%C3%B6%20W%C3%B6rld%40Python'
หรือ

โค้ด: เลือกทั้งหมด

import urllib
f = 'My URL'
urllib.urlencode(f)
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 97