msabramo / requests-unixsocket

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

InvalidURL #35

Closed disarticulate closed 5 years ago

disarticulate commented 7 years ago
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

PeteDevoy commented 7 years ago

I assume you figured this out but it looks like you are using / instead of %2f for the socket path. See the readme