AttributeError: 'HTTPMessage' object has no attribute 'getheaders'

Issue #206 resolved
Tarek Ziadé repo owner created an issue

This bug is from the latest codeline of distribute ( from tarek's branch).
It should be fixed in there. Following the recent changes in cpython line, I
saw that distribute was monkeypatching httplib and a fix was made in
cpython, perhaps the same should be ported here.

It will be observed, whenever the setup tries to download the package from
pypi or any other remote repo.

File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/command/install.py",
line 101, in do_egg_install
cmd.run()
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/command/easy_install.py",
line 345, in run
self.easy_install(spec, not self.no_deps)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/command/easy_install.py",
line 565, in easy_install
return self.install_item(None, spec, tmpdir, deps, True)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/command/easy_install.py",
line 617, in install_item
self.process_distribution(spec, dist, deps)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/command/easy_install.py",
line 669, in process_distribution
[requirement], self.local_index, self.easy_install
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/pkg_resources.py",
line 544, in resolve
dist = best[req.key] = env.best_match(req, self, installer)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/pkg_resources.py",
line 786, in best_match
return self.obtain(req, installer) # try and download/install
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/pkg_resources.py",
line 798, in obtain
return installer(requirement)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/command/easy_install.py",
line 572, in easy_install
self.local_index
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/package_index.py",
line 492, in fetch_distribution
dist = find(requirement)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/package_index.py",
line 475, in find
location=self.download(dist.location, tmpdir)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/package_index.py",
line 414, in download
found = self._download_url(scheme.group(1), spec, tmpdir)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/package_index.py",
line 663, in _download_url
return self._attempt_download(url, filename)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/package_index.py",
line 672, in _attempt_download
headers = self._download_to(url, filename)
File
"/usr/local/lib/python3.3/site-packages/distribute-0.6.17dev-py3.3.egg/setuptools/package_index.py",
line 583, in _download_to
content_length = headers.getheaders("Content-Length")[0]
AttributeError: 'HTTPMessage' object has no attribute 'getheaders'

Comments (7)

  1. Former user Account Deleted

    I'm getting this, too:

    root@Luke-LT-Ubuntu:/usr/local/src/Python-3.2# easy_install setproctitle
    Searching for setproctitle
    Reading http://pypi.python.org/simple/setproctitle/
    Reading http://code.google.com/p/py-setproctitle/
    Best match: setproctitle 1.1.2
    Downloading http://pypi.python.org/packages/source/s/setproctitle/setproctitle-1.1.2.zip#md5=52f99a78cbdd1b0036bf41b4512442e7
    Traceback (most recent call last):
      File "/usr/local/python/bin/easy_install", line 9, in <module>
        load_entry_point('distribute==0.6.17', 'console_scripts', 'easy_install')()
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/command/easy_install.py", line 1864, in main
        with_ei_usage(lambda:
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/command/easy_install.py", line 1845, in with_ei_usage
        return f()
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/command/easy_install.py", line 1868, in <lambda>
        distclass=DistributionWithoutHelpCommands, **kw
      File "/usr/local/python/lib/python3.2/distutils/core.py", line 149, in setup
        dist.run_commands()
      File "/usr/local/python/lib/python3.2/distutils/dist.py", line 919, in run_commands
        self.run_command(cmd)
      File "/usr/local/python/lib/python3.2/distutils/dist.py", line 938, in run_command
        cmd_obj.run()
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/command/easy_install.py", line 345, in run
        self.easy_install(spec, not self.no_deps)
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/command/easy_install.py", line 572, in easy_install
        self.local_index
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/package_index.py", line 492, in fetch_distribution
        dist = find(requirement)
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/package_index.py", line 475, in find
        location=self.download(dist.location, tmpdir)
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/package_index.py", line 414, in download
        found = self._download_url(scheme.group(1), spec, tmpdir)
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/package_index.py", line 663, in _download_url
        return self._attempt_download(url, filename)
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/package_index.py", line 672, in _attempt_download
        headers = self._download_to(url, filename)
      File "/usr/local/python/lib/python3.2/site-packages/distribute-0.6.17-py3.2.egg/setuptools/package_index.py", line 583, in _download_to
        content_length = headers.getheaders("Content-Length")[0]
    AttributeError: 'HTTPMessage' object has no attribute 'getheaders'
    
  2. Former user Account Deleted

    My quick (and dirty) fix was to edit package_index.py, comment out line 583, adding my own, like so:

                    #content_length = headers.getheaders("Content-Length")[0]
                    content_length = fp.getheader("Content-Length")[0]
    
  3. Tarek Ziadé reporter

    so, the fix is:

    diff --git a/setuptools/package_index.py b/setuptools/package_index.py
    --- a/setuptools/package_index.py
    +++ b/setuptools/package_index.py
    @@ -580,7 +580,7 @@
                 size = -1
                 if "content-length" in headers:
                     # Some servers return multiple Content-Length headers :(
    -                content_length = headers.getheaders("Content-Length")[0]
    +                content_length = headers.get("Content-Length")
                     size = int(content_length)
                     self.reporthook(url, filename, blocknum, bs, size)
                 tfp = open(filename,'wb')
    
    

    This works with all flavors of this class.

    Preparing 0.6.19 now

  4. Mike Bayer

    its building now (on 0.6.19 is that what you meant ?) - its into the tests so its fixed, thanks !

  5. Log in to comment