Search code examples
pythonhttpexception

http.client.HTTPException: got more than 100 headers


Since google did not find anything regarding error "http.client.HTTPException: got more than 100 headers", I created this question.

>>> import http.client as h
>>> conn = h.HTTPConnection("www.coursefinders.com")
>>> conn.request("HEAD","/")
>>> conn.getresponse();
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/http/client.py", line 1148, in getresponse
    response.begin()
  File "/usr/lib/python3.4/http/client.py", line 376, in begin
    self.headers = self.msg = parse_headers(self.fp)
  File "/usr/lib/python3.4/http/client.py", line 267, in parse_headers
    raise HTTPException("got more than %d headers" % _MAXHEADERS)
http.client.HTTPException: got more than 100 headers

What does this exception mean and how should I properly handle this type of error? Site works OK in browser.


Solution

  • Here is a solution that doesn't involve changing library's py files:

    import httplib  # or http.client if you're on Python 3
    httplib._MAXHEADERS = 1000
    

    Just put that at the top of your code