Python3.6请求网站时报错:http.client.RemoteDisconnected: Remote end closed connection without response
调整前的代码段:
data = urllib.request.urlopen(url).read()
运行时报错:
http.client.RemoteDisconnected: Remote end closed connection without response
调整后代码段:
headers = {'User-Agent': 'User-Agent:Mozilla/5.0'}
data1 = urllib.request.Request(url, headers=headers)
data = urllib.request.urlopen(data1).read()
正常运行
原因:服务器限制了部分User-Agent的访问。
博客指出Python3.6请求网站时出现http.client.RemoteDisconnected错误。原代码运行报错,调整后添加了包含User - Agent的请求头,代码正常运行。原因是服务器限制了部分User - Agent的访问。
4267

被折叠的 条评论
为什么被折叠?



