python-hyper / hyper

HTTP/2 for Python.
http://hyper.rtfd.org/en/latest/
MIT License
1.05k stars 191 forks source link

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

Open PATAPOsha opened 5 years ago

PATAPOsha commented 5 years ago
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.

KostyaEsmukov commented 5 years ago

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
ramazk commented 4 years ago

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