Skip to content

KeyError: 'content-length' #17

Description

@kamakazikamikaze

I am calling the script as follows:

python docker_pull.py registry.access.redhat.com/ubi8/ubi

The script will output the following:

78afc5364ad2: Downloading...

And then it fails:

Traceback (most recent call last):
  File "docker_pull.py", line 155, in <module>
    unit = int(bresp.headers['Content-Length']) / 50
  File "C:\Users\<NTID>\AppData\Local\Programs\Python\Python37\lib\site-packages\requests\structures.py", line 52, in __getitem__
    return self._store[key.lower()][1]
KeyError: 'content-length'

I've made a few adjustments to your script, primarily adding the proxies= option for calls to requests functions as I'm stuck behind a proxy. This allows me to communicate with the Redhat registry. So line 155 is actually line 141 as referenced below.

unit = int(bresp.headers['Content-Length']) / 50

I've added a print statement to dump the bresp.headers and Content-Length is not in there:

{
  'Accept-Ranges': 'bytes',
  'Content-Type': 'text/plain',
  'ETag': '"ced9e6d20e1ac931689399b68b0dd6a4:1588112355"',
  'Last-Modified': 'Tue, 28 Apr 2020 22:03:16 GMT',
  'Server': 'AkamaiNetStorage',
  'Vary': 'Accept-Encoding',
  'Date': 'Mon, 18 May 2020 17:57:51 GMT',
  'Transfer-Encoding': 'chunked',
  'X-Docker-Size': '-1',
  'Cache-Control': 'proxy-revalidate',
  'Connection': 'Keep-Alive',
  'Content-Encoding': 'gzip'
}

I've confirmed with a machine at home (different OS and no proxy) that the same error is experienced. I understand that the script relies on the Docker HTTPS API v2 so I apologize if the redhat registry is actually v1. I'm new to docker and do not know how to check for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions