Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requests 2.12 has broken 'er? #24

Closed
jtpaasch opened this issue Nov 15, 2016 · 4 comments
Closed

Requests 2.12 has broken 'er? #24

jtpaasch opened this issue Nov 15, 2016 · 4 comments

Comments

@jtpaasch
Copy link

Has the just-released Requests 2.12 library broken something? Just today, a unix socket request gives me the error "URL has invalid label".

Steps to reproduce:

  1. On a machine with Docker running and a user that can access /var/run/docker.sock.

  2. Make a virtual environment (with Python 3.4+) and install requests_unixsocket:

    pyvenv venv
    . venv/bin/activate
    pip install --upgrade pip
    pip install requests-unixsocket

  3. Note that requests is 2.12.

  4. In a python interpreter try to get a list of docker containers:

    >>> import requests_unixsocket
    >>> session = requests_unixsocket.Session()
    >>> r = session.get("http+unix://%2Fvar%2Frun%2Fdocker.sock/containers/json")

  5. It throws the error.

    requests.exceptions.InvalidURL: URL has an invalid label.

If I do the same with requests 2.11.1, it works fine.

The requests 2.12 release notes say there's an upgrade to IDNA2008.

@mreithub
Copy link

I can confirm this (was trying to build new ondevice debian packages and the resulting packages couldn't connect to the UNIX control socket, failing with the same message as your attempts. Pinning to requests==2.11.1 works).

For the sake of completeness, here's my stack trace:

ERROR:root:Caught exception
Traceback (most recent call last):
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/packages/idna/core.py", line 327, in uts46_remap
    raise IndexError()
IndexError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/models.py", line 370, in prepare_url
    host = idna.encode(host, uts46=True).decode('utf-8')
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/packages/idna/core.py", line 340, in encode
    s = uts46_remap(s, std3_rules, transitional)
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/packages/idna/core.py", line 332, in uts46_remap
    _unot(code_point), pos + 1, repr(domain)))
requests.packages.idna.core.InvalidCodepoint: Codepoint U+0025 not allowed at position 1 in '%2froot%2f.config%2fondevice%2fondevice.sock'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/ondevice/lib/python3.5/site-packages/ondevice/commands/status_cmd.py", line 43, in run
    s = client.getState(False)
  File "/usr/lib/ondevice/lib/python3.5/site-packages/ondevice/control/client.py", line 61, in getState
    return _getJson('/state')
  File "/usr/lib/ondevice/lib/python3.5/site-packages/ondevice/control/client.py", line 51, in _getJson
    r = _getSession().get(url)
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/sessions.py", line 501, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/sessions.py", line 474, in request
    prep = self.prepare_request(req)
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/sessions.py", line 407, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/models.py", line 302, in prepare
    self.prepare_url(url, params)
  File "/usr/lib/ondevice/lib/python3.5/site-packages/requests/models.py", line 372, in prepare_url
    raise InvalidURL('URL has an invalid label.')
requests.exceptions.InvalidURL: URL has an invalid label.

@graingert
Copy link

requests no-longer prepares URLs that do not start with "http://" or "https://" see also https://github.com/kennethreitz/requests/issues/3734

@habnabit
Copy link
Contributor

habnabit commented Dec 8, 2016

Seems to be fixed as of at least 2.12.3.

@msabramo
Copy link
Owner

Yeah there was a problem in some versions of requests, but it's fixed now. I just tested last night and it worked great: httpie/httpie-unixsocket#10 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants