调整前的代码段:
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的访问。