votes up 2

URL has an invalid label.

Exception Class:

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):
                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 += '@'

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://*')
r = req.prepare()

Working Version (FIXED)

import requests

# there is no wildcard now
req = requests.Request('GET', '')
r = req.prepare()


Jun 03, 2021 snowLimit answer

Add a possible fix

Please authorize to post fix