Answer the question
In order to leave comments, you need to log in
How to check if the proxy is working through which I want to send requests, python?
I need to start Selenium by writing that it will work through a proxy - webdriver.Firefox(proxy=self.proxy), but if the proxy is not working, then the browser is endlessly loaded. How can I check if the proxy is working using Python? (os windows)
Answer the question
In order to leave comments, you need to log in
It is possible so;
import urllib
import socket
socket.setdefaulttimeout(2) # timeout. increase for slow proxies
try:
urllib.urlopen(
"http://ya.ru",
proxies={'http':'http://example.com:8080'} # your proxy here
)
except IOError:
print "Bad proxy!" # do it if proxy connect is failed
else:
print "All was OK" # do it if all ok
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question