votes up 3

invalid version number '%s'

Package:
ansible
github stars 49704
Exception Class:
ValueError

Raise code

    version_re = re.compile(r'^(\d+) \. (\d+) (\. (\d+))? ([ab](\d+))?$',
                            RE_FLAGS)

    def parse(self, vstring):
        match = self.version_re.match(vstring)
        if not match:
            raise ValueError("invalid version number '%s'" % vstring)

        (major, minor, patch, prerelease, prerelease_num) = \
            match.group(1, 2, 4, 5, 6)

        if patch:
            self.version = tuple(map(int, [major, minor, patch]))
        else:

Ways to fix

votes up 1 votes down

The exception is thrown when calling StrictVersion.

StrictVersion is version numbering. A version number consists of two or three dot-separated numeric components, with an optional "pre-release" tag on the end. The pre-release tag consists of the letter 'a' or 'b' followed by a number.

When you are using invalid version numbers, you will get an error.

Here is some invalid version numbers example:

        1
        2.7.2.2
        1.3.a4
        1.3pl1
        1.3c4

To reproduce an error

from distutils.version import StrictVersion

version = StrictVersion('1.3.a4')
print(version)

Fix code:

from distutils.version import StrictVersion

version = StrictVersion('0.9.6')
print(version)
Jul 27, 2021 anonim answer
anonim 13.0k

Add a possible fix

Please authorize to post fix