GithubHelp home page GithubHelp logo

msabramo / requests-unixsocket Goto Github PK

View Code? Open in Web Editor NEW
205.0 7.0 28.0 83 KB

Use requests to talk HTTP via a UNIX domain socket

License: Apache License 2.0

Python 98.54% Makefile 1.46%
python requests http unix-domain-socket

requests-unixsocket's Introduction

requests-unixsocket

Latest Version on PyPI

Use requests to talk HTTP via a UNIX domain socket

Usage

Explicit

You can use it by instantiating a special Session object:

import json

import requests_unixsocket

session = requests_unixsocket.Session()

r = session.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
registry_config = r.json()['RegistryConfig']
print(json.dumps(registry_config, indent=4))

Implicit (monkeypatching)

Monkeypatching allows you to use the functionality in this module, while making minimal changes to your code. Note that in the above example we had to instantiate a special requests_unixsocket.Session object and call the get method on that object. Calling requests.get(url) (the easiest way to use requests and probably very common), would not work. But we can make it work by doing monkeypatching.

You can monkeypatch globally:

import requests_unixsocket

requests_unixsocket.monkeypatch()

r = requests.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
assert r.status_code == 200

or you can do it temporarily using a context manager:

import requests_unixsocket

with requests_unixsocket.monkeypatch():
    r = requests.get('http+unix://%2Fvar%2Frun%2Fdocker.sock/info')
    assert r.status_code == 200

Abstract namespace sockets

To connect to an abstract namespace socket (Linux only), prefix the name with a NULL byte (i.e.: 0) - e.g.:

import requests_unixsocket

session = requests_unixsocket.Session()
res = session.get('http+unix://\0test_socket/get')
print(res.text)

For an example program that illustrates this, see examples/abstract_namespace.py in the git repo. Since abstract namespace sockets are specific to Linux, the program will only work on Linux.

See also

requests-unixsocket's People

Contributors

avian2 avatar dependabot[bot] avatar esben avatar habnabit avatar kobla avatar msabramo avatar puremourning avatar rantydave avatar wrouesnel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

requests-unixsocket's Issues

Recent issues installing on OS X and Python 3.5.1

$ pip install -U requests-unixsocket
Collecting requests-unixsocket
  Downloading requests-unixsocket-0.1.5.tar.gz
    Complete output from command python setup.py egg_info:
    ERROR:root:Error parsing
    Traceback (most recent call last):
      File "/Users/user/Projects/project/.env/versions/3.5.1/envs/myenv/lib/python3.5/site-packages/pbr/core.py", line 111, in pbr
        attrs = util.cfg_to_args(path, dist.script_args)
      File "/Users/user/Projects/project/.env/versions/3.5.1/envs/myenv/lib/python3.5/site-packages/pbr/util.py", line 264, in cfg_to_args
        wrap_commands(kwargs)
      File "/Users/user/Projects/project/.env/versions/3.5.1/envs/myenv/lib/python3.5/site-packages/pbr/util.py", line 566, in wrap_commands
        cmdclass = ep.resolve()
      File "/Users/user/Projects/project/.env/versions/3.5.1/envs/myenv/lib/python3.5/site-packages/pkg_resources/__init__.py", line 2235, in resolve
        module = __import__(self.module_name, fromlist=['__name__'], level=0)
    ImportError: No module named 'monolithic'
    error in setup command: Error parsing /private/var/folders/cb/cxxqz_g94jd1x5tjwrklxgd00000gn/T/pip-build-r8bqv_7b/requests-unixsocket/setup.cfg: ImportError: No module named 'monolithic'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/cb/cxxqz_g94jd1x5tjwrklxgd00000gn/T/pip-build-r8bqv_7b/requests-unixsocket/

session.post return None when server return http error code

session.post return None when server return http error code
example curl get 400 code:

curl --unix-socket /tmp/.kavhttpd -i -X POST -H "Content-Type:application/json" -d '{"object":"/home/dpdk-17.11.1-3.10.0_693.el7.x86_64.aaarpm"}' http://localhost/api/v3.0/scanfile
HTTP/1.0 400 Bad Request
Connection: close
Content-Type: text/plain
Server: KAVHTTPD/1.0
X-KAV-ProtocolVersion: 3
Date: Mon, 03 Apr 2023 07:01:47 GMT
Content-Length: 42

{
    "error": "Cannot scan not a file"
}

At this scene, if use requests_unixsocket session to post, I get the return is None, I can't get the http response code or content..

Requests 2.12 has broken 'er?

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.

Potential dependency conflicts between requests-unixsocket and urllib3

Hi, as shown in the following full dependency graph of requests-unixsocket, requests-unixsocket requires urllib3 >=1.8 , while the installed version of requests(2.22.0) requires urllib3 <1.26,>=1.21.1.

According to Pip's “first found wins” installation strategy, urllib3 1.25.7 is the actually installed version.

Although the first found package version urllib3 1.25.7 just satisfies the later dependency constraint (urllib3 <1.26,>=1.21.1), it will lead to a build failure once developers release a newer version of urllib3.

Dependency tree--------

requests-unixsocket - 0.2.0
| +- requests(install version:2.22.0 version range:>=1.1)
| | +- certifi(install version:2019.11.28 version range:>=2017.4.17)
| | +- chardet(install version:3.0.4 version range:<3.1.0,>=3.0.2)
| | +- idna(install version:2.8 version range:>=2.5,<2.9)
| | +- urllib3(install version:1.25.7 version range:<1.26,>=1.21.1)
| +- urllib3(install version:1.25.7 version range:>=1.8)

Thanks for your attention.
Best,
Neolith

0.2.0: pytest warnings

First of all with current pytest.ini pytest fails

+ /usr/bin/python3 -Bm pytest -ra
ERROR: usage: __main__.py [options] [file_or_dir] [file_or_dir] [...]
__main__.py: error: unrecognized arguments: --pep8
  inifile: /home/tkloczko/rpmbuild/BUILD/requests-unixsocket-0.2.0/pytest.ini
  rootdir: /home/tkloczko/rpmbuild/BUILD/requests-unixsocket-0.2.0

After remove pytest.ini it shows some warnings

+ /usr/bin/python3 -Bm pytest -ra
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.9, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/tkloczko/rpmbuild/BUILD/requests-unixsocket-0.2.0
plugins: forked-1.3.0, shutil-1.7.0, virtualenv-1.7.0, expect-1.1.0, cov-2.11.1, httpbin-1.0.0, xdist-2.2.1, flake8-1.0.7, timeout-1.4.2, betamax-0.8.1, pyfakefs-4.4.0, freezegun-0.4.2, cases-3.4.6, case-1.5.3, isort-1.3.0, aspectlib-1.5.2, mock-3.6.0, hypothesis-6.12.0, asyncio-0.15.1, toolbox-0.5, xprocess-0.17.1, flaky-3.7.0
collected 5 items

requests_unixsocket/tests/test_requests_unixsocket.py .....                                                                                                          [100%]

============================================================================= warnings summary =============================================================================
requests_unixsocket/tests/test_requests_unixsocket.py::test_unix_domain_adapter_ok
requests_unixsocket/tests/test_requests_unixsocket.py::test_unix_domain_adapter_url_with_query_params
requests_unixsocket/tests/test_requests_unixsocket.py::test_unix_domain_adapter_monkeypatch
  /usr/lib/python3.8/site-packages/waitress/adjustments.py:441: DeprecationWarning: In future versions of Waitress clear_untrusted_proxy_headers will be set to True by default. You may opt-out by setting this value to False, or opt-in explicitly by setting this to True.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/warnings.html
====================================================================== 5 passed, 3 warnings in 0.17s =======================================================================

Abstract namespace unix socket

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

Error if the path to the socket is greater than 70ish characters

I ran into an issue where I had a path to a socket that looked like this:

 %2Fstorage%2Ftestroot%2F123456789%2F123456789111%2Fdata%2Flocal_auth.sock

Which is 73 characters long. When prefixed with http+unix, the full path looks like:

 http+unix://%2Fstorage%2Ftestroot%2F123456789%2F123456789111%2Fdata%2Flocal_auth.sock

When passed to requests, the following error occurs:

File "/usr/local/updated-openssl/lib/python3.4/site-packages/requests_unixsocket/init.py", line 60, in post
File "/usr/local/updated-openssl/lib/python3.4/site-packages/requests_unixsocket/init.py", line 46, in request
File "/usr/local/updated-openssl/lib/python3.4/site-packages/requests/sessions.py", line 461, in request
File "/usr/local/updated-openssl/lib/python3.4/site-packages/requests/sessions.py", line 394, in prepare_request
File "/usr/local/updated-openssl/lib/python3.4/site-packages/requests/models.py", line 295, in prepare
File "/usr/local/updated-openssl/lib/python3.4/site-packages/requests/models.py", line 364, in prepare_url
requests.exceptions.InvalidURL: URL has an invalid label.

Which is in turn triggered by this:

Traceback (most recent call last):
File "/usr/local/updated-openssl/lib/python3.4/site-packages/requests/models.py", line 362, in prepare_url
UnicodeError: encoding with 'idna' codec failed (UnicodeError: label empty or too long)

Digging around in the source for models.py, it looks like it extracts the host (which is the path to the socket above), and then performs:

host = host.encode('idna').decode('utf-8')

This will fail in accordance with the IDNA RFC, which states:

The conversions between ASCII and non-ASCII forms of a domain name are accomplished by algorithms called ToASCII and ToUnicode. These algorithms are not applied to the domain name as a whole, but rather to individual labels. For example, if the domain name is www.example.com, then the labels are www, example, and com. ToASCII or ToUnicode are applied to each of these three separately.

The details of these two algorithms are complex, and are specified in RFC 3490. The following gives an overview of their function.

ToASCII leaves unchanged any ASCII label, but will fail if the label is unsuitable for the Domain Name System. If given a label containing at least one non-ASCII character, ToASCII will apply the Nameprep algorithm, which converts the label to lowercase and performs other normalization, and will then translate the result to ASCII using Punycode[16] before prepending the four-character string "xn--".[17] This four-character string is called the ASCII Compatible Encoding (ACE) prefix, and is used to distinguish Punycode encoded labels from ordinary ASCII labels. The ToASCII algorithm can fail in several ways; for example, the final string could exceed the 63-character limit of a DNS name. A label for which ToASCII fails cannot be used in an internationalized domain name.

My interpretation of the error is that if the path to the socket is rather long, this fails. Is there a suggested workaround other than symlinking the socket file to something short?

mounting retry adapter

I am wondering if there is a way to mount retry adapter to unix_socket session.

Here is the code snippet:

        from requests.adapters import HTTPAdapter
        from requests.packages.urllib3.util.retry import Retry

        sess = requests_unixsocket.Session()

        HTTP_REQUEST_RETRIES = 3
        HTTP_RETRY_BACKOFF_FACTOR = 0.3
        HTTP_RETRY_FORCELIST = (500, 502, 504) 

        retry = Retry(total=HTTP_REQUEST_RETRIES,
                      read=HTTP_REQUEST_RETRIES,
                      connect=HTTP_REQUEST_RETRIES,
                      backoff_factor=HTTP_RETRY_BACKOFF_FACTOR,
                      status_forcelist=HTTP_RETRY_FORCELIST)

        adapter = HTTPAdapter(max_retries=retry)
        sess.mount('http+unix://', adapter)
        

and here is there error:

   requesting POST http+unix://%2Frun%2Fmqerd%2Fnginx.sock/apicall
   error: 'http+unix' - Traceback (most recent call last):
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/proton/tools/client.py", line 294, in handle_untrusted_msg
     response = self._handle_cloud_unlock(data)
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/proton/tools/client.py", line 146, in _handle_cloud_unlock
     response = self.sess.request("POST", url, headers=headers, data=encoded_body)
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/requests/sessions.py", line 508, in request
     resp = self.send(prep, **send_kwargs)
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/requests/sessions.py", line 618, in send
     r = adapter.send(request, **kwargs)
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/requests/adapters.py", line 405, in send
     conn = self.get_connection(request.url, proxies)
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/requests/adapters.py", line 309, in get_connection
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/urllib3/poolmanager.py", line 279, in connection_from_url
     pool_kwargs=pool_kwargs)
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/urllib3/poolmanager.py", line 227, in connection_from_host
     return self.connection_from_context(request_context)
   File "/opt/venvs/op-proton/lib/python3.5/site-packages/urllib3/poolmanager.py", line 237, in connection_from_context
     pool_key_constructor = self.key_fn_by_scheme[scheme]
 KeyError: 'http+unix'

Any help is appreciated!

Getting "permission denied" error, while user has permissions on the file

I am able to do a "curl" on a file socket:

    curl --unix-socket /home/carolg/datahub68.sock http:

but I get a Permission denied when using requests_unixsocket

import requests_unixsocket
session = requests_unixsocket.Session()

url = "http+unix://home/carolg/datahub68.sock"
r = session.get(url, timeout=10)

I am calling the curl command and the python code with the same unix user

Here is the error:

Traceback (most recent call last):
  File "/genap2_venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/genap2_venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/genap2_venv/lib/python3.6/site-packages/requests_unixsocket/adapters.py", line 32, in connect
    sock.connect(socket_path)
PermissionError: [Errno 13] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/genap2_venv/lib/python3.6/site-packages/requests/adapters.py", line 445, in send
    timeout=timeout
  File "/genap2_venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/genap2_venv/lib/python3.6/site-packages/urllib3/util/retry.py", line 367, in increment
    raise six.reraise(type(error), error, _stacktrace)
  File "/genap2_venv/lib/python3.6/site-packages/urllib3/packages/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/genap2_venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/genap2_venv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output
    self.send(msg)
  File "/usr/lib/python3.6/http/client.py", line 964, in send
    self.connect()
  File "/genap2_venv/lib/python3.6/site-packages/requests_unixsocket/adapters.py", line 32, in connect
    sock.connect(socket_path)
urllib3.exceptions.ProtocolError: ('Connection aborted.', PermissionError(13, 'Permission denied'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/genap2_venv/lib/python3.6/site-packages/requests/sessions.py", line 525, in get
    return self.request('GET', url, **kwargs)
  File "/genap2_venv/lib/python3.6/site-packages/requests/sessions.py", line 512, in request
    resp = self.send(prep, **send_kwargs)
  File "/genap2_venv/lib/python3.6/site-packages/requests/sessions.py", line 622, in send
    r = adapter.send(request, **kwargs)
  File "/genap2_venv/lib/python3.6/site-packages/requests/adapters.py", line 495, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', PermissionError(13, 'Permission denied'))

requests-unixsocket should use the same timeout interface as requests.

It seems like requests-unixsocket currently has its own way of setting timeouts, which differs from requests itself.

  • The default for requests-unixsocket is 60s unlike request's default of no timeout.
  • The timeout is set as a constructor parameter of UnixAdapter, which is inaccessible, if one uses requests_unixsocket.Session.

Packaging warnings

When packaging this for Arch Linux, the following warnings are displayed in regards to setup.cfg:

UserWarning: Usage of dash-separated 'author-email' will not be supported in future versions.
Please use the underscore name 'author_email' instead
UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions.
Please use the underscore name 'description_file' instead
UserWarning: Usage of dash-separated 'home-page' will not be supported in future versions.
Please use the underscore name 'home_page' instead

Cannot import

# python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests_unixsocket
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/requests_unixsocket/__init__.py", line 4, in <module>
    from .adapters import UnixAdapter
  File "/usr/local/lib/python2.7/dist-packages/requests_unixsocket/adapters.py", line 5, in <module>
    from requests.packages.urllib3.connection import HTTPConnection
ImportError: No module named packages.urllib3.connection
# pip show urllib3

---
Name: urllib3
Version: 1.7.1
Location: /usr/lib/python2.7/dist-packages
Requires:
# pip show requests-unixsocket

---
Name: requests-unixsocket
Version: 0.1.2
Location: /usr/local/lib/python2.7/dist-packages
Requires: requests

Error when using urllib3 2.x.x release

I am trying to run a requests with a UNIX socket but it fails using the latest versions in PyPI. I guess it is related to the change in major version of urllib3 2.0.0 that happened in PyPI roughly 1 month ago

$ python3 -m venv  my_venv
(my_venv) $  . ./my_venv/bin/activate
(my_venv) $ pip install requests-unixsocket
Collecting requests-unixsocket
  Using cached requests_unixsocket-0.3.0-py2.py3-none-any.whl (11 kB)
Collecting requests>=1.1
  Using cached requests-2.31.0-py3-none-any.whl (62 kB)
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (197 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.4-py3-none-any.whl (61 kB)
Collecting urllib3<3,>=1.21.1
  Using cached urllib3-2.0.2-py3-none-any.whl (123 kB)
Collecting certifi>=2017.4.17
  Downloading certifi-2023.5.7-py3-none-any.whl (156 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 157.0/157.0 kB 1.5 MB/s eta 0:00:00
Installing collected packages: urllib3, idna, charset-normalizer, certifi, requests, requests-unixsocket
Successfully installed certifi-2023.5.7 charset-normalizer-3.1.0 idna-3.4 requests-2.31.0 requests-unixsocket-0.3.0 urllib3-2.0.2

[notice] A new release of pip available: 22.3.1 -> 23.1.2
[notice] To update, run: pip install --upgrade pip

(my_venv) $ cat test.py
import requests
import requests_unixsocket
requests_unixsocket.monkeypatch()
requests.get('http+unix://%2Frun%2Fuser%2F4876%2Fadari_server_834977.socket')
(my_venv) $ python3 test.py
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/tmp/my_venv/lib64/python3.11/site-packages/requests_unixsocket/__init__.py", line 51, in get
    return request('get', url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/my_venv/lib64/python3.11/site-packages/requests_unixsocket/__init__.py", line 46, in request
    return session.request(method=method, url=url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/my_venv/lib64/python3.11/site-packages/requests/sessions.py", line 589, in request
    resp = self.send(prep, **send_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/my_venv/lib64/python3.11/site-packages/requests/sessions.py", line 703, in send
    r = adapter.send(request, **kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/my_venv/lib64/python3.11/site-packages/requests/adapters.py", line 486, in send
    resp = conn.urlopen(
           ^^^^^^^^^^^^^
  File "/var/tmp/my_venv/lib64/python3.11/site-packages/urllib3/connectionpool.py", line 790, in urlopen
    response = self._make_request(
               ^^^^^^^^^^^^^^^^^^^
  File "/var/tmp/my_venv/lib64/python3.11/site-packages/urllib3/connectionpool.py", line 496, in _make_request
    conn.request(
TypeError: HTTPConnection.request() got an unexpected keyword argument 'chunked'

InvalidURL

sock = '/home/cy/geodocr/socks/GEODOCR.geodocr-time.time.59c96cf3e88d406a93bd084747b7c2d6'
import requests_unixsocket

session = requests_unixsocket.Session()

# Access /path/to/page from /tmp/profilesvc.sock
r = session.get('http+unix://'+sock+'/time')
---------------------------------------------------------------------------
InvalidURL                                Traceback (most recent call last)
<ipython-input-127-f08380141c32> in <module>()
      5 
      6 # Access /path/to/page from /tmp/profilesvc.sock
----> 7 r = session.get('http+unix://'+sock+'/time')
      8 assert r.status_code == 200

/home/cy/anaconda3/envs/geodocr/lib/python3.6/site-packages/requests/sessions.py in get(self, url, **kwargs)
    499 
    500         kwargs.setdefault('allow_redirects', True)
--> 501         return self.request('GET', url, **kwargs)
    502 
    503     def options(self, url, **kwargs):

/home/cy/anaconda3/envs/geodocr/lib/python3.6/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    472             hooks = hooks,
    473         )
--> 474         prep = self.prepare_request(req)
    475 
    476         proxies = proxies or {}

/home/cy/anaconda3/envs/geodocr/lib/python3.6/site-packages/requests/sessions.py in prepare_request(self, request)
    405             auth=merge_setting(auth, self.auth),
    406             cookies=merged_cookies,
--> 407             hooks=merge_hooks(request.hooks, self.hooks),
    408         )
    409         return p

/home/cy/anaconda3/envs/geodocr/lib/python3.6/site-packages/requests/models.py in prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
    300 
    301         self.prepare_method(method)
--> 302         self.prepare_url(url, params)
    303         self.prepare_headers(headers)
    304         self.prepare_cookies(cookies)

/home/cy/anaconda3/envs/geodocr/lib/python3.6/site-packages/requests/models.py in prepare_url(self, url, params)
    383 
    384         if not host:
--> 385             raise InvalidURL("Invalid URL %r: No host supplied" % url)
    386 
    387         # In general, we want to try IDNA encoding the hostname if the string contains

InvalidURL: Invalid URL 'http+unix:///home/cy/geodocr/socks/GEODOCR.geodocr-time.time.59c96cf3e88d406a93bd084747b7c2d6/time': No host supplied

I looked at IDNA and don't see anything wrong there. python is 3.6

New release ?

Hi,
the last release is pretty old and I can see changes in the main module, could you make a new release?
Thank you!

Monkey patch breaks request.post()

With the monkey patch technique (and perhaps others, I have not checked) requests.post() appears to break on both socket and standard TCP/IP connections. E.g.

import requests
import requests_unixsocket

requests_unixsocket.monkeypatch()

r = requests.post('http+unix://%2Fvar%2Frun%2Fexample.sock/example-endpoint')
#TypeError: request() got an unexpected keyword argument 'json'

r = requests.post('http://eample.com')
#TypeError: request() got an unexpected keyword argument 'json'

I have submitted PR #17 which appears to fix the issue.

Thanks for this package btw!

-Peter

ResourceWarning: unclosed socket

Hello!

I'm getting a warning about the socket being unclosed. I'm using requests_unixsocket.Session() in a context manager, so I was expecting it to be closed for me.

To reproduce:

$ python3
>>> import requests_unixsocket
>>> import warnings
>>> warnings.simplefilter('default')
>>> with requests_unixsocket.Session() as session:
...    snap_info = session.get('http+unix://%2Frun%2Fsnapd.socket/v2/snaps/core')
... 
__main__:2: ResourceWarning: unclosed <socket.socket fd=4, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0, raddr=/run/snapd.socket>
$ lsb_release -d
Description:    Ubuntu 16.04.3 LTS
$ python3 --version
Python 3.5.2
$ pip list | grep requests-unixsocket
requests-unixsocket (0.1.5)

Installation fails

I do have git installed, but installation fails with following message:

$ python setup.py build
[...]
Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository. Are you sure that git is installed?
error in setup command: Error parsing /tmp/yaourt-tmp-bruno/aur-python-requests-unixsocket/src/requests-unixsocket-0.1.5/setup.cfg: Exception: Versioning for this project
 requires either an sdist tarball, or access to an upstream git repository. Are you sure that git is installed?

It installs correctly through pip though..

This is on an Arch x86_64 machine.

GET parameters stripped from URL

In a request like http+unix://%2Fvar%2Frun%2Fdocker.sock/containers/nginx/logs?timestamp=true, the GET parameters at the end of the URL are stripped out. This is due to UnixHTTPConnection.request only passing through the URL's path to its parent function (relevant line of code).

The problem is easily fixed by removing the aforementioned line or by removing UnixHTTPConnection.request entirely. I'd issue a pull request, but I'm unsure of the motivation behind the current behaviour and want to avoid inadvertently breaking other requests.

0.2.0 tag missing

Pypi indicates that the newest version is 0.2.0. However, the newest tag in this repo is 0.1.5. Could you add the missing tag?

Test probot

This is just a test issue to see if my probot app is receiving web hooks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.