Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.7.6: urllib3.exceptions.ProxySchemeUnknown #5297

Closed
rafaduran opened this issue Dec 23, 2019 · 18 comments
Closed

Python 3.7.6: urllib3.exceptions.ProxySchemeUnknown #5297

rafaduran opened this issue Dec 23, 2019 · 18 comments

Comments

@rafaduran
Copy link

Proxy setup without scheme is not working on Python 3.7.6

While it works on Python 3.7.5:

Python 3.7.5 (default, Nov 23 2019, 05:59:34) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get("http://httpbin.org/get", proxies={"http": "103.250.166.4:6666"})
<Response [200]>

Is not under Python 3.7.6

Python 3.7.6 (default, Dec 21 2019, 08:28:11) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get("http://httpbin.org/get", proxies={"http": "103.250.166.4:6666"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=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/requests/adapters.py", line 412, in send
    conn = self.get_connection(request.url, proxies)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 309, in get_connection
    proxy_manager = self.proxy_manager_for(proxy)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 199, in proxy_manager_for
    **proxy_kwargs)
  File "/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py", line 470, in proxy_from_url
    return ProxyManager(proxy_url=url, **kw)
  File "/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py", line 420, in __init__
    raise ProxySchemeUnknown(proxy.scheme)
urllib3.exceptions.ProxySchemeUnknown: Not supported proxy scheme None

It seems that some changes on Python urllib.parse.urlparse brake requests.utils.prepend_scheme_if_needed

>>> utils.prepend_scheme_if_needed('103.250.166.4:6666', 'http')
'103.250.166.4://6666'

So it looks like this utils has to update to match Python changes (I think the change that produces this is python/cpython@5a88d50). In both cases I'm using requests 2.22.0.

Reporting here since urllib.parse.urlparse behaviour is wrong in both Python versions and I think the problem is requests.utils.prepend_scheme_if_needed problem:

Python 3.7.5

>>> from urllib import parse
>>> parse.urlparse("103.250.166.4:6666")
ParseResult(scheme='', netloc='', path='103.250.166.4:6666', params='', query='', fragment='')

Python 3.7.6

>>> from urllib import parse
>>> parse.urlparse("103.250.166.4:6666")
ParseResult(scheme='103.250.166.4', netloc='', path='6666', params='', query='', fragment='')
@sethmlarson
Copy link
Member

sethmlarson commented Dec 23, 2019

Thanks for reporting this issue and doing investigation!

You can fix this by using http://<ip>:<port> instead of just an IP.

@Crackde
Copy link

Crackde commented Dec 29, 2019

you can solve the problem??
i have the same issue with python 3.8

Proxy setup without scheme is not working on Python 3.7.6

While it works on Python 3.7.5:

Python 3.7.5 (default, Nov 23 2019, 05:59:34) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get("http://httpbin.org/get", proxies={"http": "103.250.166.4:6666"})
<Response [200]>

Is not under Python 3.7.6

Python 3.7.6 (default, Dec 21 2019, 08:28:11) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.get("http://httpbin.org/get", proxies={"http": "103.250.166.4:6666"})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=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/requests/adapters.py", line 412, in send
    conn = self.get_connection(request.url, proxies)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 309, in get_connection
    proxy_manager = self.proxy_manager_for(proxy)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 199, in proxy_manager_for
    **proxy_kwargs)
  File "/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py", line 470, in proxy_from_url
    return ProxyManager(proxy_url=url, **kw)
  File "/usr/local/lib/python3.7/site-packages/urllib3/poolmanager.py", line 420, in __init__
    raise ProxySchemeUnknown(proxy.scheme)
urllib3.exceptions.ProxySchemeUnknown: Not supported proxy scheme None

It seems that some changes on Python urllib.parse.urlparse brake requests.utils.prepend_scheme_if_needed

>>> utils.prepend_scheme_if_needed('103.250.166.4:6666', 'http')
'103.250.166.4://6666'

So it looks like this utils has to update to match Python changes (I think the change that produces this is python/cpython@5a88d50). In both cases I'm using requests 2.22.0.

Reporting here since urllib.parse.urlparse behaviour is wrong in both Python versions and I think the problem is requests.utils.prepend_scheme_if_needed problem:

Python 3.7.5

>>> from urllib import parse
>>> parse.urlparse("103.250.166.4:6666")
ParseResult(scheme='', netloc='', path='103.250.166.4:6666', params='', query='', fragment='')

Python 3.7.6

>>> from urllib import parse
>>> parse.urlparse("103.250.166.4:6666")
ParseResult(scheme='103.250.166.4', netloc='', path='6666', params='', query='', fragment='')

you can solve the problem??
i have same issue with python 3.8

@sethmlarson
Copy link
Member

@Crackde:

You can fix this by using http://<ip>:<port> instead of just an IP.

@damarvin
Copy link

damarvin commented Jan 6, 2020

yes, this fixes the issue for 3.7.6 or 3.8.x
either by --proxy http://<ip>:<port>
or in (Windows') %APPDATA%\pip\pip.ini, [global] section:
http://<ip>:<port>

@joh-ku
Copy link

joh-ku commented Jan 7, 2020

I observed the same error. As already mentioned above, i also can solve the problem by adding a leading http:// to the --proxy command line argument or in %APPDATA%\pip\pip.ini configuration file.

System information:
OS: Windows 10 Enterprise (Build 17134)
Python: 3.8.1 (x86)
pip: 19.3.1

@nateprewitt
Copy link
Member

It looks like Seth has answered this and it's working as expected now. Going to resolve, thanks everyone.

@flaxsh
Copy link

flaxsh commented Feb 18, 2020

The fix is not applicable if one is using another library and has no direct control over the proxy urls.

I think the solution should be to fix the way utils.prepend_scheme_if_needed method calls the urllib3 helpers. as it currently is not working as intended (it should at least not produce invalid urls):

utils.prepend_scheme_if_needed('103.250.166.4:6666', 'http')
'103.250.166.4://6666'

The issues seems that urlsplit searches for the first ":" and assumes everything to the right to be the scheme - unless it contains an illegal character(a non-alphanumeric character except +-.).
This also overrides the default scheme that the prepend_scheme_if_needed passes to urlparse, which passes it to urlsplit.

103.250.166.4:6666 --> scheme = 103.250.166.4, path=6666

prefixing it with "//" - as is expected by urlparse - works:

//103.250.166.4:6666 --> scheme = None (default is used) , netloc=103.250.166.4:6666

Maybe prepend_scheme can first check for the presence of a scheme and then call urlparse with the prepended "//"?
Or is this an issue with urllib?

@ShunTono
Copy link

ShunTono commented May 6, 2020

When I try to update by conda, I had received this following report

Traceback (most recent call last):
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\exceptions.py", line 1079, in call
return func(*args, **kwargs)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\cli\main.py", line 84, in _main
exit_code = do_call(args, p)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\cli\conda_argparse.py", line 82, in do_call
return getattr(module, func_name)(args, parser)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\cli\main_update.py", line 20, in execute
install(args, parser, 'update')
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\cli\install.py", line 265, in install
should_retry_solve=(_should_retry_unfrozen or repodata_fn != repodata_fns[-1]),
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 117, in solve_for_transaction
should_retry_solve)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 158, in solve_for_diff
force_remove, should_retry_solve)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 262, in solve_final_state
ssc = self._collect_all_metadata(ssc)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\common\io.py", line 88, in decorated
return f(*args, **kwds)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 415, in _collect_all_metadata
index, r = self._prepare(prepared_specs)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 1011, in _prepare
self.subdirs, prepared_specs, self._repodata_fn)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\index.py", line 228, in get_reduced_index
repodata_fn=repodata_fn)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 105, in query_all
result = tuple(concat(executor.map(subdir_query, channel_urls)))
File "C:\Users\Shungo\anaconda3\lib\concurrent\futures_base.py", line 598, in result_iterator
yield fs.pop().result()
File "C:\Users\Shungo\anaconda3\lib\concurrent\futures_base.py", line 435, in result
return self.__get_result()
File "C:\Users\Shungo\anaconda3\lib\concurrent\futures_base.py", line 384, in __get_result
raise self._exception
File "C:\Users\Shungo\anaconda3\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 98, in
package_ref_or_match_spec))
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 110, in query
self.load()
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 174, in load
_internal_state = self._load()
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 248, in _load
repodata_fn=self.repodata_fn)
File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 485, in fetch_repodata_remote_request
timeout=timeout)
File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\adapters.py", line 412, in send
conn = self.get_connection(request.url, proxies)
File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\adapters.py", line 309, in get_connection
proxy_manager = self.proxy_manager_for(proxy)
File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\adapters.py", line 199, in proxy_manager_for
**proxy_kwargs)
File "C:\Users\Shungo\anaconda3\lib\site-packages\urllib3\poolmanager.py", line 470, in proxy_from_url
return ProxyManager(proxy_url=url, **kw)
File "C:\Users\Shungo\anaconda3\lib\site-packages\urllib3\poolmanager.py", line 420, in init
raise ProxySchemeUnknown(proxy.scheme)
urllib3.exceptions.ProxySchemeUnknown: Not supported proxy scheme None

Last one mean it is similar problem.
However, I could not understand how to change setting proxy.

@ShunTono
Copy link

ShunTono commented May 6, 2020

I try to change it, however, the manner may be bad

(base) C:\Users\Shungo>conda update conda
Collecting package metadata (current_repodata.json): failed

>>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<

Traceback (most recent call last):
  File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\adapters.py", line 412, in send
    conn = self.get_connection(request.url, proxies)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\adapters.py", line 305, in get_connection
    proxy_url = parse_url(proxy)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\urllib3\util\url.py", line 392, in parse_url
    return six.raise_from(LocationParseError(source_url), None)
  File "<string>", line 3, in raise_from
urllib3.exceptions.LocationParseError: Failed to parse: https://<ip>:<port>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\exceptions.py", line 1079, in __call__
    return func(*args, **kwargs)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\cli\main.py", line 84, in _main
    exit_code = do_call(args, p)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\cli\conda_argparse.py", line 82, in do_call
    return getattr(module, func_name)(args, parser)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\cli\main_update.py", line 20, in execute
    install(args, parser, 'update')
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\cli\install.py", line 265, in install
    should_retry_solve=(_should_retry_unfrozen or repodata_fn != repodata_fns[-1]),
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 117, in solve_for_transaction
    should_retry_solve)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 158, in solve_for_diff
    force_remove, should_retry_solve)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 262, in solve_final_state
    ssc = self._collect_all_metadata(ssc)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\common\io.py", line 88, in decorated
    return f(*args, **kwds)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 415, in _collect_all_metadata
    index, r = self._prepare(prepared_specs)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\solve.py", line 1011, in _prepare
    self.subdirs, prepared_specs, self._repodata_fn)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\index.py", line 228, in get_reduced_index
    repodata_fn=repodata_fn)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 105, in query_all
    result = tuple(concat(executor.map(subdir_query, channel_urls)))
  File "C:\Users\Shungo\anaconda3\lib\concurrent\futures\_base.py", line 598, in result_iterator
    yield fs.pop().result()
  File "C:\Users\Shungo\anaconda3\lib\concurrent\futures\_base.py", line 435, in result
    return self.__get_result()
  File "C:\Users\Shungo\anaconda3\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception
  File "C:\Users\Shungo\anaconda3\lib\concurrent\futures\thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 98, in <lambda>
    package_ref_or_match_spec))
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 110, in query
    self.load()
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 174, in load
    _internal_state = self._load()
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 248, in _load
    repodata_fn=self.repodata_fn)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\conda\core\subdir_data.py", line 485, in fetch_repodata_remote_request
    timeout=timeout)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\Shungo\anaconda3\lib\site-packages\requests\adapters.py", line 414, in send
    raise InvalidURL(e, request=request)
requests.exceptions.InvalidURL: Failed to parse: https://<ip>:<port>

@ningfc
Copy link

ningfc commented Nov 15, 2020

I sove this by modify pip_vendor\requests\adapters.py
def get_connection(self, url, proxies=None):
"""Returns a urllib3 connection for the given URL. This should not be
called from user code, and is only exposed for use when subclassing the
:class:HTTPAdapter <requests.adapters.HTTPAdapter>.

    :param url: The URL to connect to.
    :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
    :rtype: urllib3.ConnectionPool
    """
    proxy = select_proxy(url, proxies)
    print(proxy)

    proxy = None #<<<<<< ADD THIS LINE
    if proxy:
        proxy = prepend_scheme_if_needed(proxy, 'http')
        proxy_url = parse_url(proxy)
        if not proxy_url.host:
            raise InvalidProxyURL("Please check proxy URL. It is malformed"
                                  " and could be missing the host.")
        proxy_manager = self.proxy_manager_for(proxy)
        conn = proxy_manager.connection_from_url(url)
    else:
        # Only scheme should be lower case
        parsed = urlparse(url)
        url = parsed.geturl()
        conn = self.poolmanager.connection_from_url(url)

    return conn

@faaafo
Copy link

faaafo commented Apr 2, 2021

@sethmlarson

You can fix this by using http://<ip>:<port> instead of just an IP.

Sorry I still don't get what I should alter here:

proxy={'http': '91.98.102.84:1080', 'https': '91.98.102.84:1080'}
import requests
url='https://httpbin.org/ip'
r=requests.get(url,proxies=proxy,timeout=7)
ProxySchemeUnknown: Not supported proxy scheme None

@sethmlarson
Copy link
Member

proxy={'http': 'http://91.98.102.84:1080', 'https': 'http://91.98.102.84:1080'}

@Srutna
Copy link

Srutna commented Jul 18, 2021

proxy={'http': 'http://91.98.102.84:1080', 'https': 'http://91.98.102.84:1080'}

This solution doesn't work with python 3.9.1 version, by running the below code, I get Errors:

import requests
proxies = {'https': 'http://207.144.111.230:8080', 'http':'http://207.144.111.230:8080'}
url = 'https://httpbin.org/ip'
r = requests.get(url, proxies=proxies)

By running the code I get:

Traceback (most recent call last):
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py", line 96, in create_connection
    raise err
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\connection.py", line 86, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 353, in connect
    conn = self._new_conn()
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000026AD7D9F490>: Failed to establish a new connection: [WinError 10060] Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\urllib3\util\retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError("<urllib3.connection.HTTPSConnection object at 0x0000026AD7D9F490>: Failed to establish a new connection: [WinError 10060] Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato")))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\texas\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError("<urllib3.connection.HTTPSConnection object at 0x0000026AD7D9F490>: Failed to establish a new connection: [WinError 10060] Impossibile stabilire la connessione. Risposta non corretta della parte connessa dopo l'intervallo di tempo oppure mancata risposta dall'host collegato")))

Translation of the error's last line:
Unable to establish connection. Incorrect response from the connected party after the time interval or no response from the connected host
The requests lib version is 2.25.1

@Srija-ravi
Copy link

Try like this it will be working ,

import requests
url = "http://httpbin.org/ip"
proxy_host = "proxy.crawlera.com"
proxy_port = "8010"
proxy_auth = ":"
proxies = {
"https": "https://{}@{}:{}/".format(proxy_auth, proxy_host, proxy_port),
"http": "http://{}@{}:{}/".format(proxy_auth, proxy_host, proxy_port)
}
r = requests.get(url, proxies=proxies, verify=False)

@josuebustos
Copy link

josuebustos commented Sep 23, 2021

I had to re-edit my answer.

urllib3 and requests proxy implementations are distinctly different.

From requests:
Based on the requests Proxies section; https://docs.python-requests.org/en/master/user/advanced/#proxies

Notice there is no "s" in https property value.

import requests

proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
               ^
}

requests.get('http://example.org', proxies=proxies)

From urllib3:
Based on the the urllib3 Proxies section; https://urllib3.readthedocs.io/en/stable/advanced-usage.html?highlight=proxy#proxies

>>> import urllib3
>>> proxy = urllib3.ProxyManager('http://localhost:3128/')
>>> proxy.request('GET', 'http://google.com/')

@Zeyrox-Zy
Copy link

Make sure you have a trailing forward slash at the very end of the url string.

"https://190.7.141.66:8080/"
                          ^

I spend hours trying to understand why it wasn't working.

I hope it helps the next dev.

not working for me :(

@josuebustos
Copy link

@Zeyrox-Zy I just updated my answer.

@fast590
Copy link

fast590 commented Oct 5, 2021

proxy = {'http':'http://127.0.0.1:8000/', 'https':'http://127.0.0.1:8000/'}
url ='http://httpbin.org/ip'
r = requests.get(url, proxies=proxy)

this is not working as well.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests