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:
ūüôŹ Scream for help to Ukraine
Today, 14th August 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this ūüė†, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

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