[PYTHON] urllib3.exceptions.LocationParseError: Measures against Failed to parse

Problems with code written in Python, such as commands installed with pip. Apparently it's failing to parse the URL. It's a problem that is local and depends on the environment on the user side, but for that reason there was no solution, so make a note of it.

Background

When I was using atcoder-tools, it suddenly stopped working properly around the beginning of November. It doesn't mean that the tool didn't have an update, or that it didn't stop working with update because I didn't insert update in the first place. I'm not sure because I really don't know.

Looking at the error

  File "/usr/lib/python3/dist-packages/requests/models.py", line 380, in prepare_url
    scheme, auth, host, port, path, query, fragment = parse_url(url)
  File "/usr/lib/python3/dist-packages/urllib3/util/url.py", line 392, in parse_url
    return six.raise_from(LocationParseError(source_url), None)
  File "<string>", line 2, in raise_from
    urllib3.exceptions.LocationParseError

There is a log like that. Try to figure out if the problem is the six or urllib3 module.

Remedy 1

$ pip3 install six==1.15.0

The version of the six module is old and may be malfunctioning. If you have a log like module'six' has no attribute'ensure_str', this is probably the case. Since ensure_str is added to six after 1.15.0, it becomes the above command. In fact, it seems that some people have improved this. However, this did not fix me. Even if you do this, it will not change, so people may want to try the following remedy 2.

Remedy 2

$ pip3 insatll --upgrade urllib3

This also updates the version of urllib3 to the latest version. Now that I'm working fine, I can't say I'll fix it.

Summary

It made me sad because it was a pretty silly reason. I wonder if the version downgrade was caught at some point even though it was operating normally halfway. I did install, uninstall, etc. of the command on the way, but maybe that's the reason? I do not understand

Recommended Posts

urllib3.exceptions.LocationParseError: Measures against Failed to parse
Parse JSON file to object