0

I currently want to create an application which downloads something with changing proxies. At the moment, I have to enter the proxies into a list by myself and if they aren't working, the application just crashes. Can I somehow either get a list of working proxies at the start of the application or can I check a proxy for its functionality before it sends out an error? Thanks for your help in advance, Till

I've tried different api's to get rotating proxies, but when one of them doesn't work, I still have the problem of it crashing.

proxy = session.get('https://gimmeproxy.com/api/getProxy?supportsHttps=TRUE&ipPort=true&country=DE').text

proxies = {
"http": "http://" + proxy,
"https": "http://" + proxy,
}
r = session.get('https://api.ipify.org/?format=json', proxies=proxies)
print(r)

I expect the output to be the IP of the proxy I'm using, but sometimes I get different errors (for instance 'Connection refused' or 'Cannot connect to proxy.') and the application crashes afterwards

Tiiill
  • 47
  • 1
  • 3
  • use Exception handling https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module – waynetech Jun 30 '19 at 12:55
  • Thanks! Is there a way to let a exception pass when a time limit is exceeded? – Tiiill Jun 30 '19 at 14:15
  • yes, you can set a timeout ```r = session.get('https://api.ipify.org/?format=json', timeout=10)``` and catch the exception and retry ```except requests.exceptions.Timeout:``` – waynetech Jun 30 '19 at 14:39
  • It's working, thank you! – Tiiill Jun 30 '19 at 20:21

0 Answers0