[1289] Fixes for problems when cleaning url.

For some urls with a broken netloc the encoding to idna breaks, and to resolve this we do what requests does, which is to raise an InvalidURL exception.

Rather than break totally, which would be valid, we will try a simple cleanup of common netloc problems (any trailing . should be fine though).  We should make sure that fix_url is centralised so we can use it elsewhere too.