D
D
Dasha_PROgrammer2021-06-19 15:57:23
Python
Dasha_PROgrammer, 2021-06-19 15:57:23

How to login with python requests proxy?

I'm trying to parse pages with the https protocol using a proxy with authorization and without authorization.
For an example of parsing https://2ip.ru/
I found many ways to parse using requests, however, when parsing the page https://2ip.ru/ , I see that my ip address does not change. How to solve this problem? How can I change the proxy address?
Proxy bought

Example with a proxy without authorization:

import requests

url = 'http://45.235.110.66:53281'
r = requests.get('http://2ip.ru/', proxies={'http':url})
print(r.status_code)
print(r.text)

# Вывод:
# html со старым ip или бывает такой вывод:
# requests.exceptions.ProxyError: HTTPConnectionPool(host='45.235.110.66', port=53281): Max retries exceeded with url: #http://2ip.ru/ (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection #object at 0x0000021BC08F94C0>: Failed to establish a new connection: [WinError 10060] Попытка установить соединение #была безуспешной, т.к. от другого компьютера за требуемое время не получен нужный отклик, или было разорвано уже #установленное соединение из-за неверного отклика уже подключенного компьютера')))


An example of a proxy with authorization:
import requests
from requests.auth import HTTPProxyAuth

s = requests.Session()

proxies = {
    "http": "http://45.87.255.43:59923",
    "https": "https://45.87.255.43:59923"
}

auth = HTTPProxyAuth("KmUxr4kY", "gFAa7tku")

s.proxies = proxies
s.auth = auth  # Set authorization parameters globally

ext_ip = s.get('http://2ip.ru/')
print(ext_ip.text)

# вывод:
# ничего

# вывод:
# ничего

ip address doesn't change :(

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question