votes up 2

URL has an invalid label.

Package:
Exception Class:
InvalidURL

Raise code

        # non-ASCII characters. This allows users to automatically get the correct IDNA
        # behaviour. For strings containing only ASCII characters, we need to also verify
        # it doesn't start with a wildcard (*), before allowing the unencoded hostname.
        if not unicode_is_ascii(host):
            try:
                host = self._get_idna_encoded_host(host)
            except UnicodeError:
                raise InvalidURL('URL has an invalid label.')
        elif host.startswith(u'*'):
            raise InvalidURL('URL has an invalid label.')

        # Carefully reconstruct the network location
        netloc = auth or ''
        if netloc:
            netloc += '@'
🙏 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 0 votes down

Summary: Make sure your ulr does not start with a wildcard '*'.

Code to reproduce (WRONG)

import requests

# url cannot start with wildcard      '*'
req = requests.Request('GET', 'https://*fixexception.com')
r = req.prepare()

Working Version (FIXED)

import requests

# there is no wildcard now
req = requests.Request('GET', 'https://fixexception.com')
r = req.prepare()

print(r)

Jun 03, 2021 snowLimit answer

Add a possible fix

Please authorize to post fix