稍等片刻,正在加载中...

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)

posted @ 2020-05-07 14:57  一切皆往事  阅读(2207)  评论(0编辑  收藏  举报