0

I am trying to create a proxy tester, I have been trying to trouble shoot this for days and can't seem to figure out the issue. Every time I run it, no matter what the proxy is (I've tried many) I get the error

"requests.exceptions.ProxyError: HTTPSConnectionPool(host='advanced.name', port=443): Max retries exceeded with url: /freeproxy (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f9a7e0ea400>: Failed to establish a new connection: [Errno -2] Name or service not known')))"

The message sounds like the proxy is bad but I've tried a boat load that I know work. Here is the code I have

import requests
from requests.exceptions import Timeout

headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'en-GB,en;q=0.5',
    'DNT': '1',
    'Connection': 'keep-alive',
    'Upgrade-Insecure-Requests': '1',
}

proxy = {
    "http": "http//132.145.54.142:1080",
    "https": "https//132.145.54.142:1080"

}

proxy_Test = requests.get("https://advanced.name/freeproxy", headers=headers, proxies=proxy, timeout=10)
print(proxy_Test.status_code)
if proxy_Test.status_code == 200:
    print("this proxy is good:" + str(proxy).replace("{", " ").replace("}", "").replace("'", ""))
else:
    print("This proxy is no good")
try:
    x = requests.get("http://www.google.com", headers=headers, proxies=proxy, timeout=10)
except Timeout:
    print("error found")
PythonC
  • 39
  • 2
  • 7
  • there is a syntax error in you code.lack of colon in `"http": "http//132.145.54.142:1080"`.it should be `"http": "http://132.145.54.142:1080"` – nay Jun 24 '21 at 06:22
  • Hmm, when I run it it actually waits the given time for a timeout but then still throws the error. If the proxy is bad it should just print "This proxy is no good". I've tried about 10 different proxies as well. – PythonC Jun 24 '21 at 06:41
  • due to you proxy `132.145.54.142:1080` is available on the internet.I try it myself.first you can not set http and https as same port.second you proxy not setup well.you can test it through `curl -v -x https://132.145.54.142:1080 ifconfig.co` or other program. – nay Jun 24 '21 at 06:48

2 Answers2

1

If you want to hide your ip adress, you can use torrequest instead of requests:

pip install torrequest

Example code (more here):

from torrequest import TorRequest

with TorRequest() as tr:
    response = tr.get('http://ipecho.net/plain')
    print(response.text)

    tr.reset_identity()

    response = tr.get('http://ipecho.net/plain')
    print(response.text)

You need to install Tor browser first.

Matteo Bianchi
  • 434
  • 1
  • 4
  • 19
-1

This website is filtered in your country, and the proxy you've set:

proxy = {     "HTTPS": "http://95.66.151.101:8080" }

Did not work either, so you have to find another proxy

Zoe
  • 27,060
  • 21
  • 118
  • 148