msabramo / requests-unixsocket

Use requests to talk HTTP via a UNIX domain socket
Apache License 2.0
207 stars 29 forks source link

Abstract namespace unix socket #18

Closed vetal4444 closed 7 years ago

vetal4444 commented 8 years ago

Add support for abstruct namespace unix socket. Currently it is raised requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory')).

msabramo commented 8 years ago

I don't know how to reproduce this. If you can give me a code snippet that reproduces the issue, then I'll consider reopening the issue.

Thanks!

vetal4444 commented 7 years ago

In [1]: import requests_unixsocket In [2]: session = requests_unixsocket.Session() In [3]: resp = session.get("@test_socket")

MissingSchema: Invalid URL '@test_socket': No schema supplied. Perhaps you meant http://@test_socket?

msabramo commented 7 years ago

Ah ok. I wasn't familiar with abstract namespace sockets. Going to reopen so I can investigate this.

Do you have a particular program (Python or otherwise) that creates an abstract namespace socket that you're trying to communicate with?

msabramo commented 7 years ago

I wonder if you tried replacing @ with \0? It seems that's the way to reference abstract domain sockets in C and Python.

msabramo commented 7 years ago

You might want to try:

resp = session.get("http+unix://\0test_socket")
msabramo commented 7 years ago

See https://utcc.utoronto.ca/~cks/space/blog/python/AbstractUnixSocketsAndPeercred

hoefling commented 5 years ago

Looks like the URL parsing fails:

$ python --version
Python 3.6.9
$ pip show requests-unixsocket | grep Version
Version: 0.1.5
$ python -c "from requests_unixsocket import Session; Session().get('http+unix://\0test_socket')"
Traceback (most recent call last):
  File "/home/hoefling/projects/.venvs/bjoern-py36/lib/python3.6/site-packages/requests/models.py", line 379, in prepare_url
    scheme, auth, host, port, path, query, fragment = parse_url(url)
  File "/home/hoefling/projects/.venvs/bjoern-py36/lib/python3.6/site-packages/urllib3/util/url.py", line 234, in parse_url
    raise LocationParseError(url)
urllib3.exceptions.LocationParseError: Failed to parse: http+unix://test_socket

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/hoefling/projects/.venvs/bjoern-py36/lib/python3.6/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/home/hoefling/projects/.venvs/bjoern-py36/lib/python3.6/site-packages/requests/sessions.py", line 519, in request
    prep = self.prepare_request(req)
  File "/home/hoefling/projects/.venvs/bjoern-py36/lib/python3.6/site-packages/requests/sessions.py", line 462, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/home/hoefling/projects/.venvs/bjoern-py36/lib/python3.6/site-packages/requests/models.py", line 313, in prepare
    self.prepare_url(url, params)
  File "/home/hoefling/projects/.venvs/bjoern-py36/lib/python3.6/site-packages/requests/models.py", line 381, in prepare_url
    raise InvalidURL(*e.args)
requests.exceptions.InvalidURL: Failed to parse: http+unix://test_socket

While curl requests the endpoint just fine:

$ curl --abstract-unix-socket test_socket -i http://127.0.0.1/
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
HTTP/1.1 200 yo
Connection: Keep-Alive
Transfer-Encoding: chunked
msabramo commented 5 years ago

I get the same thing. I think it might be due to a change in urllib3.

With a new virtualenv, I get the same error as you, but if I downgrade urllib3:

pip install urllib3==1.20

then that error goes away.