Add tests to test_invalid_url for `InvalidSchema`

In b149be5d `PreparedRequest` was made to skip `parse_url` for e.g.
`$HOST:$PORT`, which results in `MissingSchema` not being raised for
`localhost:3128`.


I have created https://github.com/shazow/urllib3/issues/466 to possibly handle the "oddball schemes" in urllib3 directly.

EDIT: not their job.


@jvantuyl
Can you remember and elaborate on why you've made this change (https://github.com/kennethreitz/requests/commit/b149be5d864cc7f65ac22113db3d0e4d2ed2b49e)?


@blueyed I elaborated on this change in the issue you opened on shazow/urllib3. This allows for third-party developers to create adapters using the `file` protocol and has the side-effect of allowing `data` URLs as well even though requests will not handle them.


Basically, it makes requests extensible with other protocols.  It doesn't _add_ support, but it makes it at least possible.  Two implementations (which I haven't tested in ages):

[file protocol](/jvantuyl/requests-file)
[data protocol](/jvantuyl/requests-data)

I originally used them for testing and ad-hoc usage of some CLI tools I built for deployment.


Also I'm fairly certain it allowed @asmeurer to use the file protocol in conda/conda.


And, syntactically, "localhost:8000" does parse as a URL.  It just uses the unknown scheme localhost.  Interestingly, that's _exactly_ the error you're getting (although as an AssertionError, which is probably bad form).  Perhaps you could replace that assertion with a different error (say UnrecognizedScheme), check for it, then implement the fallback behavior?


I see.

So it's probably expected and sane to get a `InvalidSchema: No connection adapters were found for 'localhost:5432'` exception instead of `MissingSchema: Invalid URL 'localhost:5432': No schema supplied. Perhaps you meant http://localhost?` then.

I've thought about adding a regex that would let it fall through, but it doesn't change much in the end.

The expected outcome should get added as test however.

@jvantuyl 

> the error you're getting (although as an AssertionError, which is probably bad form). Perhaps you could replace that assertion with a different error (say UnrecognizedScheme), check for it, then implement the fallback behavior?

I do not understand this. It appears to be a proper exception already (`InvalidSchema`).
Where do you mean to add the check and fallback?

I came to this issue through pip and the handling of its proxy setting initially (IIRC, and unrelated).


You are correct.  I was just responding to the raising of AssertionError with a made-up error.  I forgot that such an exception existed.  Looks like that's been noted as #2222.


conda uses https://github.com/conda/conda/blob/e082781cad83e0bc6a41a2870b605f4ee08bbd4d/conda/connection.py#L74-L120. I think I took it from pip. 


My problems centered around urllib.util.url.parse_url doing some interesting splitting when certain characters were involved and then further mangling inside of requests.models.prepare_url.  If you have the wrong characters in your URL, interesting things can happen (and all of them are pretty clearly incorrect).  I suspect that those same issues wouldn't be any better for anybody else if someone has exciting and interesting file paths. :/


I've changed the PR to add more tests, which document/test the current behavior.


Suits me. :cake:


We haven't come across that issue in conda, but assumedly the fix is to first `urllib.parse.quote` the parts of the path.