1

I've been trying to access a website through a proxy in python using the requests module (I'm accessing api.ipify.org in my example because it should print the proxy's ip). I've tested the proxy using the same program before, and it has worked. But sometimes randomly when I run it, it gives me an error. Here is my code:

import requests

proxies = {
 "http": "39.100.18.200:8080",
 "https": "39.100.18.200:8080",
}
r = requests.get("http://api.ipify.org/", proxies=proxies)
print(r.text)

It should print: 39.100.18.200 And it has before, but randomly it will give me this error:

Traceback (most recent call last):
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 1322, in getresponse
    response.begin()
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 303, in begin
    version, status, reason = self._read_status()
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\http\client.py", line 272, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\urllib3\util\retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='39.100.18.200', port=8080): Max retries exceeded with url: http://api.ipify.org/ (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mmein\OneDrive\Desktop\pywork\nitrothruproxy.py", line 7, in <module>
    r = requests.get("http://api.ipify.org/", proxies=proxies)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\requests\adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPConnectionPool(host='39.100.18.200', port=8080): Max retries exceeded with url: http://api.ipify.org/ (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))
[Finished in 2.4s with exit code 1]
[shell_cmd: python -u "C:\Users\mmein\OneDrive\Desktop\pywork\nitrothruproxy.py"]
[dir: C:\Users\mmein\OneDrive\Desktop\pywork]
[path: C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\Scripts\;C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\;C:\Users\mmein\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\mmein\AppData\Local\Programs\Python\Python38\;C:\Program Files\MySQL\MySQL Shell 8.0\bin\;C:\Users\mmein\AppData\Local\Microsoft\WindowsApps;C:\Users\mmein\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\mmein\AppData\Local\atom\bin;C:\Users\mmein\OneDrive\Desktop\gecko\geckodriver.exe;C:\ffmpeg\bin;C:\MinGW\bin;C:\Program Files\heroku\bin;C:\Users\mmein\AppData\Roaming\npm;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;]
HoneyPoop
  • 473
  • 1
  • 6
  • 25

0 Answers0