hyper icon indicating copy to clipboard operation
hyper copied to clipboard

Using hyper.contrib.HTTP20Adapter with requests.session ignores proxies.

Open PATAPOsha opened this issue 6 years ago • 2 comments

import requests
from hyper.contrib import HTTP20Adapter

sess = requests.session()
sess.mount('http://', HTTP20Adapter())
sess.mount('https://', HTTP20Adapter())

sess.proxies.update({
                    'http': 'http://login:pass@ip:port',
                    'https': 'https://login:pass@ip:port'
                })

sess.get(url)

Actually, the problem is described in the title. Request is sent using machine`s real ip, not proxy.

PATAPOsha avatar Sep 28 '18 16:09 PATAPOsha

Probably that's because you're using a version from PyPI, which is way behind the current development branch, see #364 .

As a workaround, try installing hyper from github directly, that should fix your issue:

pip install --upgrade https://github.com/Lukasa/hyper/archive/development.tar.gz

KostyaEsmukov avatar Sep 30 '18 09:09 KostyaEsmukov

Probably that's because you're using a version from PyPI, which is way behind the current development branch, see #364 .

As a workaround, try installing hyper from github directly, that should fix your issue:

pip install --upgrade https://github.com/Lukasa/hyper/archive/development.tar.gz

Same problem here, but after upgrading to 0.8.0.dev0 I now receive error:

>>> s.get('https://api.myip.com', proxies=proxies, verify=False).json()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/hyper/contrib.py", line 116, in send
    request.headers
  File "/usr/local/lib/python3.7/site-packages/hyper/common/connection.py", line 110, in request
    method=method, url=url, body=body, headers=headers
  File "/usr/local/lib/python3.7/site-packages/hyper/http11/connection.py", line 246, in request
    self.connect()
  File "/usr/local/lib/python3.7/site-packages/hyper/http11/connection.py", line 180, in connect
    timeout=self._timeout
  File "/usr/local/lib/python3.7/site-packages/hyper/http11/connection.py", line 53, in _create_tunnel
    resp = conn.get_response()
  File "/usr/local/lib/python3.7/site-packages/hyper/http11/connection.py", line 287, in get_response
    self._sock.fill()
  File "/usr/local/lib/python3.7/site-packages/hyper/common/bufsocket.py", line 169, in fill
    raise ConnectionResetError()
ConnectionResetError

ramazk avatar Oct 03 '19 08:10 ramazk