Sarvesh Dubey
Sarvesh Dubey

Reputation: 11

How to check if internet connection from is proxy is lost or present?

I am building a Selenium bot and have to use that script multiple times in a go. The problem with the script is that the proxy I am using rotated itself in every 10-12 mins and when it rotates, the internet connection is lost for 10-15 seconds which results in either freezing of the page or breaking the code.

I want to check the internet connection from proxy at every step in my script, if that is present, I will move forward and if not, I will wait for some 30 sec so the connection is automatically restored.

Is there any way I can check the connection? or any other better way to deal with this problem?

Upvotes: -1

Views: 215

Answers (1)

Mohammed Danok
Mohammed Danok

Reputation: 19

You could you socket to check the internet connection.

socket.gethostbyname(socket.gethostname())

Or you could use requests to check the response code if there’s connection or not.

Upvotes: 0

Related Questions