Skip to content
This repository was archived by the owner on May 28, 2022. It is now read-only.

ValueError: too many values to unpack on unexpected formats #6

Open
sithembiso opened this issue Feb 20, 2016 · 1 comment
Open

ValueError: too many values to unpack on unexpected formats #6

sithembiso opened this issue Feb 20, 2016 · 1 comment

Comments

@sithembiso
Copy link

Hi,
Excellent job on putting this library together :-)

I kept getting this error:

Traceback (most recent call last):
  File "./dimgx.py", line 494, in <module>
    _main()
  File "/home/sithembiso/Projects/dimgx/_dimgx/cmd.py", line 272, in main
    layers_dict = inspectlayers(dc, args.image)
  File "/home/sithembiso/Projects/dimgx/dimgx.py", line 338, in inspectlayers
    images = sorted(( normalizeimage(i) for i in images ), key=imagekey, reverse=True)
  File "/home/sithembiso/Projects/dimgx/dimgx.py", line 338, in <genexpr>
    images = sorted(( normalizeimage(i) for i in images ), key=imagekey, reverse=True)
  File "/home/sithembiso/Projects/dimgx/dimgx.py", line 458, in normalizeimage
    repo, tag = repo_tag.split(':')
ValueError: too many values to unpack

This was because one of the images I have on my docker images is tagged for a localhost registry. The name looks like this: localhost:5000/55893ae73513c315ba7c3000.
What would happen is that Dimgx would append :latest turning it to localhost:5000/55893ae73513c315ba7c3000:latest which is not expected according to #L458.

I solved this by adding the following because I don't care for that image:

if repo_tag.count(':') > 1:
            continue

I wanted to do something and add a pull request, but I don't know what would be the best way to handle this. Should we try and make people use regular image names of try to handle these cases as well?

Thanks

@posita
Copy link
Owner

posita commented Feb 23, 2016

@sithembiso, good spotting! PRs are highly encouraged (see the submission guidelines).

I'm embarrassed that hadn't considered your use case. 😳

However, I'm concerned that your proposed solution would break for something like localhost:5000/myimg:latest or localhost:5000/myimg:mytag though. It would also still be broken for something like localhost:5000/myimg. And never mind specifying a repo with an IPv6 address. 😮

What do you think about doing something like a regex instead? Maybe something like:

_REPO_TAG_RE = r'(?:(?P<host>[^/]+(?::(?P<port>[1-9]\d*))?)/)?(?P<img>[^:]+)(?::(?P<tag>[^:]+))?'

I just banged that out without checking it, so it may not even validate, much less work, but hopefully you get the idea? I'm sure there are improvements that could be made. For example, perhaps the [^:]+ in the img and tag groups could be more restrictive (and reflect Docker's own limitations)?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants