python爬虫错误:http.client.HTTPException: got more than 100 headers的解决方法

当遇到Python爬虫报错http.client.HTTPException: got more than 100 headers时,原因是服务器返回的请求头数量超过了默认限制。解决方法是修改最大请求头个数。

python爬虫错误:http.client.HTTPException: got more than 100 headers的解决方法

Traceback (most recent call last):
  File "C:\Users\Jonariguez\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "C:\Users\Jonariguez\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 387, in _make_request
    six.raise_from(e, None)
  File "<string>", line 2, in raise_from
  File "C:\Users\Jonariguez\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 383, in _make_request
    httplib_response = conn.getresponse()
  File "D:\Software\Python3\lib\http\client.py", line 1331, in getresponse
    response.begin()
  File "D:\Software\Python3\lib\http\client.py", line 321, in begin
    self.headers = self.msg = parse_headers(self.fp)
  File "D:\Software\Python3\lib\http\client.py", line 211, in parse_headers
    raise HTTPException("got more than %d headers" % _MAXHEADERS)
http.client.HTTPException: got more than 100 headers

错误

返回的请求头大多,超过了自定义的最大请求头个数

解决方法:

修改最大请求头个数即可。

python3

import http.client

http.client._MAXHEADERS = 1000

python2

import httplib

httplib._MAXHEADERS = 1000
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值