Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

urllib #26

Open
Mariusz89B opened this issue May 10, 2021 · 0 comments
Open

urllib #26

Mariusz89B opened this issue May 10, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Mariusz89B
Copy link

Mariusz89B commented May 10, 2021

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
@kboghe kboghe added the enhancement New feature or request label Jun 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants