#๐Ÿ”’ Issue with ProxyError

4 messages ยท Page 1 of 1 (latest)

valid matrix
#

Hey guys, have been trying to implement a bunch of proxies to my python script to effectively scrape web without facing issues pertained to rate-limiting etc.

I have bought a set of proxies, the web let's me download the updated version; I made a script to check if all of the ones are working before adding them to a list that my script (a Discord Bot) can use.

For my script I keep facing a ProxyError that I just can't get around, I have tried many ways to keep continuing with the code and wrote a couple Exceptions, however we will always get stuck and my script will stuck after fetching the Proxy that is also marked as down by the Host.

The logic of my script was just to send a basic request via that Proxy - if it returns a response within 3 seconds mark it as working, if not mark it as not working and remove from the file for further use.

Any idea?

import requests
from requests.exceptions import ProxyError, ConnectTimeout, ReadTimeout, RequestException
from urllib3.exceptions import MaxRetryError

read proxies from file

def proxyfile(file_path):
with open(file_path, 'r') as file:
proxies = [line.strip() for line in file.readlines() if line.strip()]
return proxies

testing

def test_proxy(proxy):
try:
ip, port, user, password = proxy.split(':')
proxy_url = f"http://{user}:{password}@{ip}:{port}"
proxies = {
'http': proxy_url,
'https': proxy_url
}
response = requests.get('http://httpbin.org/ip', proxies=proxies, timeout=5)
if response.status_code == 200:
print(f"Proxy {proxy} is working.")
else:
print(f"Proxy {proxy} is not working. Status Code: {response.status_code}")
except MaxRetryError:
print(f"Proxy {proxy} failed: Max retries exceeded.")
except ProxyError as e:
print(f"Proxy {proxy} failed due to proxy error: {e}")
except ConnectTimeout:
print(f"Proxy {proxy} failed due to connection timeout.")
except ReadTimeout:
print(f"Proxy {proxy} failed due to read timeout.")
except RequestException as e:
print(f"Proxy {proxy} failed: {e}")

#proxy file
proxies = proxyfile('cleaned_proxies.txt')

testing function

for proxy in proxies:
try:
test_proxy(proxy)
except Exception as e:
print(f"An unexpected error occurred with proxy {proxy}: {e}")
continue

twin stratusBOT
#

@valid matrix

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

twin stratusBOT
#

@valid matrix

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.