Help, Can't find the default proxy in requests by config

Evi1 T1me otex911 at gmail.com
Thu Feb 21 10:03:06 EST 2019


On Thursday, February 21, 2019 at 7:12:40 AM UTC-5, Evi1 T1me wrote:
> ```bash
> ~ python3
> Python 3.7.0 (default, Oct 22 2018, 14:54:27)
> [Clang 10.0.0 (clang-1000.11.45.2)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import requests
> >>> r = requests.get('https://www.baidu.com')
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 159, in _new_conn
>     (self._dns_host, self.port), self.timeout, **extra_kw)
>   File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 80, in create_connection
>     raise err
>   File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 70, in create_connection
>     sock.connect(sa)
> ConnectionRefusedError: [Errno 61] Connection refused
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 594, in urlopen
>     self._prepare_proxy(conn)
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 805, in _prepare_proxy
>     conn.connect()
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 301, in connect
>     conn = self._new_conn()
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 168, in _new_conn
>     self, "Failed to establish a new connection: %s" % e)
> urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x10e3ce550>: Failed to establish a new connection: [Errno 61] Connection refused
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
>     timeout=timeout
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
>     _stacktrace=sys.exc_info()[2])
>   File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
>     raise MaxRetryError(_pool, url, error or ResponseError(cause))
> urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10e3ce550>: Failed to establish a new connection: [Errno 61] Connection refused')))
> 
> During handling of the above exception, another exception occurred:
> 
> 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 510, in send
>     raise ProxyError(e, request=request)
> requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10e3ce550>: Failed to establish a new connection: [Errno 61] Connection refused')))
> ```
> 
> Check the proxy 
> 
> ```bash
> >>> print(requests.utils.get_environ_proxies('https://www.baidu.com'))
> {'http': 'http://127.0.0.1:8888', 'https': 'http://127.0.0.1:8888'}
> ```
> 
> Check bash environment
> 
> ```bash
> ~ set | grep proxy
> ```
> Nothing output.
> 
> ```bash
> ➜  ~ netstat -ant | grep 8888
> tcp4       5      0  127.0.0.1.54437        127.0.0.1.8888         CLOSE_WAIT
> tcp4     653      0  127.0.0.1.54436        127.0.0.1.8888         CLOSE_WAIT
> tcp4       5      0  127.0.0.1.54434        127.0.0.1.8888         CLOSE_WAIT
> ```
> 
> ```bash
> ➜  ~ lsof -i:8888
> COMMAND     PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
> JavaAppli 77714 zerop   54u  IPv6 0x975257a323b5690f      0t0  TCP localhost:54434->localhost:ddi-tcp-1 (CLOSE_WAIT)
> JavaAppli 77714 zerop   55u  IPv6 0x975257a33daa290f      0t0  TCP localhost:54436->localhost:ddi-tcp-1 (CLOSE_WAIT)
> JavaAppli 77714 zerop   56u  IPv6 0x975257a3366b600f      0t0  TCP localhost:54437->localhost:ddi-tcp-1 (CLOSE_WAIT)
> ```
> 
> ```bash
> ➜  ~ ps -ef | grep 77714
>   501 77714     1   0 11:17AM ??         3:33.55 /Applications/Burp Suite Community Edition.app/Contents/MacOS/JavaApplicationStub
>   501 84408 82855   0  5:54AM ttys002    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn 77714
> ```
> 
> Restart the application BurpSuite Community and then run the command `lsof -i:8888`, nothing out
> ```bash
> ➜  ~ lsof -i:8888
> ```
> 
> Check `HTTP_SERVER` and `HTTP_PROXY`
> 
> ```bash
> ➜  ~ echo $HTTP_SERVER
> 
> ➜  ~ echo $HTTP_PROXY
> 
> ➜  ~ echo $HTTPS_SERVER
> ```
> 
> Restart the computer and try to access Baidu as the following.
> ```bash
> >>> r = requests.get('https://www.baidu.com')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> NameError: name 'requests' is not defined
> >>> import requests
> >>> r = requests.get('https://www.baidu.com')
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 159, in _new_conn
>     (self._dns_host, self.port), self.timeout, **extra_kw)
>   File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 80, in create_connection
>     raise err
>   File "/usr/local/lib/python3.7/site-packages/urllib3/util/connection.py", line 70, in create_connection
>     sock.connect(sa)
> ConnectionRefusedError: [Errno 61] Connection refused
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 594, in urlopen
>     self._prepare_proxy(conn)
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 805, in _prepare_proxy
>     conn.connect()
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 301, in connect
>     conn = self._new_conn()
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 168, in _new_conn
>     self, "Failed to establish a new connection: %s" % e)
> urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0x102577160>: Failed to establish a new connection: [Errno 61] Connection refused
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
>     timeout=timeout
>   File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
>     _stacktrace=sys.exc_info()[2])
>   File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 398, in increment
>     raise MaxRetryError(_pool, url, error or ResponseError(cause))
> urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x102577160>: Failed to establish a new connection: [Errno 61] Connection refused')))
> 
> During handling of the above exception, another exception occurred:
> 
> 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 510, in send
>     raise ProxyError(e, request=request)
> requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.baidu.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x102577160>: Failed to establish a new connection: [Errno 61] Connection refused')))
> ```
> 
> And then check the default proxy with `urllib.request.getproxies()`
> ```bash
> >>> import urllib
> >>> print(urllib.getproxies())
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> AttributeError: module 'urllib' has no attribute 'getproxies'
> >>> print(urllib.request.getproxies())
> {'http': 'http://127.0.0.1:8888', 'https': 'http://127.0.0.1:8888'}
> ```


Solved. Check the system proxy and change it after checking all the shell env.



More information about the Python-list mailing list