Python3.6请求网站时报错:http.client.RemoteDisconnected: Remote end closed connection without response

来源:互联网 发布:用户画像建模算法 编辑:程序博客网 时间:2024/06/06 02:32

调整前的代码段:

    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的访问。



阅读全文
0 0
原创粉丝点击