NordVPN-switcher
NordVPN-switcher copied to clipboard
urllib
Some issue when using urllib on py3, why not use requests library instead? Also there is problem with the website https://ident.me/, when connection fails service will not be kept running, it need to choose second option if first one fails.
Could this maybe be a solution?
import sys
if sys.version_info[0] > 2:
from requests.exceptions import HTTPError, ConnectionError, Timeout, RequestException
else:
from requests import HTTPError, ConnectionError, Timeout, RequestException
def get_ip():
headers = set_headers(user_agent_rotator)
ip_check_websites = ['http://ip4only.me/api/',"https://ident.me/"]
ip_check_websites =ip_check_websites = ['http://ip4only.me/api/',"https://ident.me/"]
website_pick = random.choice(ip_check_websites)
ip = None
try:
request_currentip = requests.get(website_pick, headers=headers)
ip = request_currentip.text
if website_pick == 'http://ip4only.me/api/':
ip = re.search("IPv4,(.*?),Remaining", ip).group(1)
except HTTPError as e:
rotate_VPN()
except ConnectionError as e:
rotate_VPN()
except Timeout as e:
rotate_VPN()
except RequestException as e:
rotate_VPN()
except:
rotate_VPN()
return ip