Доступ к веб-сайту через прокси с запросами иногда не работает (http.client.RemoteDisconnected: удаленное закрытое соединение без ответа)

#python #proxy #python-requests #proxies

#python #прокси #python-запросы

Вопрос:

Я пытался получить доступ к веб-сайту через прокси на python, используя модуль запросов (я обращаюсь api.ipify.org в моем примере, потому что он должен печатать IP-адрес прокси-сервера). Я уже тестировал прокси, используя ту же программу, и она работала. Но иногда случайно, когда я его запускаю, он выдает ошибку. Вот мой код:

 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)
  

Он должен напечатать: 39.100.18.200
И это было раньше, но случайно это выдаст мне эту ошибку:

 Traceback (most recent call last):
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesurllib3connectionpool.py", line 665, in urlopen
    httplib_response = self._make_request(
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesurllib3connectionpool.py", line 421, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesurllib3connectionpool.py", line 416, in _make_request
    httplib_response = conn.getresponse()
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libhttpclient.py", line 1322, in getresponse
    response.begin()
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libhttpclient.py", line 303, in begin
    version, status, reason = self._read_status()
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libhttpclient.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:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesrequestsadapters.py", line 439, in send
    resp = conn.urlopen(
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesurllib3connectionpool.py", line 719, in urlopen
    retries = retries.increment(
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesurllib3utilretry.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:UsersmmeinOneDriveDesktoppyworknitrothruproxy.py", line 7, in <module>
    r = requests.get("http://api.ipify.org/", proxies=proxies)
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesrequestsapi.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesrequestsapi.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesrequestssessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesrequestssessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "C:UsersmmeinAppDataLocalProgramsPythonPython38-32libsite-packagesrequestsadapters.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:UsersmmeinOneDriveDesktoppyworknitrothruproxy.py"]
[dir: C:UsersmmeinOneDriveDesktoppywork]
[path: C:Program Files (x86)Common FilesOracleJavajavapath;C:WINDOWSsystem32;C:WINDOWS;C:WINDOWSSystem32Wbem;C:WINDOWSSystem32WindowsPowerShellv1.0;C:WINDOWSSystem32OpenSSH;C:Program FilesGitcmd;C:Program Filesnodejs;C:UsersmmeinAppDataLocalProgramsPythonPython38-32Scripts;C:UsersmmeinAppDataLocalProgramsPythonPython38-32;C:UsersmmeinAppDataLocalProgramsPythonPython38Scripts;C:UsersmmeinAppDataLocalProgramsPythonPython38;C:Program FilesMySQLMySQL Shell 8.0bin;C:UsersmmeinAppDataLocalMicrosoftWindowsApps;C:UsersmmeinAppDataLocalProgramsMicrosoft VS Codebin;C:UsersmmeinAppDataLocalatombin;C:UsersmmeinOneDriveDesktopgeckogeckodriver.exe;C:ffmpegbin;C:MinGWbin;C:Program Filesherokubin;C:UsersmmeinAppDataRoamingnpm;%USERPROFILE%AppDataLocalMicrosoftWindowsApps;]