urllib.error.HTTPError: HTTP Error 403: Forbidden


# 簡單例子
import urllib.request

request = urllib.request.Request('https://python.org')
response = urllib.request.urlopen(request)
# print(response.read().decode('utf-8'))

# 增加header
from urllib import request, parse

# url = 'http://httpbin.org/post'
url = 'https://upload.wikimedia.org/wikipedia/commons/e/e0/Caravaggio_-_Cena_in_Emmaus.jpg'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0'
}
# 構造POST表格
dict = {
    'name': 'Germey'
}
data = bytes(parse.urlencode(dict), encoding='utf8')
req = request.Request(url=url, data=data, headers=headers, method='GET')
response = request.urlopen(req)

print(response)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM