question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

if page not load using bad proxy

See original GitHub issue

`

            #Get Proxy
            mylogs.info(f'Getting New IP')
            driver.proxy = get_random_proxy(proxies)
            while True:
                driver.execute_script("window.open('https://api.ipify.org?format=json')")
                driver.switch_to.window(driver.window_handles[-1])
                json_response = json.loads(driver.find_element_by_tag_name('body').text)   
                if json_response == 0:
                    mylogs.error(f'Proxy not working retrying...')
                    driver.close()
                    driver.switch_to.window(driver.window_handles[0])
                    continue
                else:
                    proxy_ip = json_response['ip']
                    mylogs.info(f'Your new IP is: {proxy_ip}')
                    driver.close()
                    driver.switch_to.window(driver.window_handles[0])
                    break

`

can you help me to figure this problem

because if json_response == 0:

not help me and if the page not open i got crash

i nead if i get bad gateway or page not reachable make return and get new proxy until get the new IP

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wkeelingcommented, Oct 6, 2021

Thanks for asking, but it’s fine - I do it for the love of it 😁

1reaction
wkeelingcommented, Oct 6, 2021

If the response is not returning valid JSON, then json.loads() will raise an exception - it won’t be 0. So try wrapping the json.loads() call in a try/except - for example:

# Get Proxy
mylogs.info(f'Getting New IP')
driver.proxy = get_random_proxy(proxies)
while True:
    driver.execute_script("window.open('https://api.ipify.org?format=json')")
    driver.switch_to.window(driver.window_handles[-1])

    try:
        json_response = json.loads(driver.find_element_by_tag_name('body').text)
    except ValueError:
        mylogs.error(f'Proxy not working retrying...')
        driver.close()
        driver.switch_to.window(driver.window_handles[0])
        continue

    proxy_ip = json_response['ip']
    mylogs.info(f'Your new IP is: {proxy_ip}')
    driver.close()
    driver.switch_to.window(driver.window_handles[0])
    break
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix “There Is Something Wrong With the Proxy Server ...
1. Check if You Have a Stable Internet Connection · 2. Restore Your Proxy Server to Its Default Settings · 3. Disabling Your...
Read more >
How to fix "There is something wrong with the proxy server ...
How to Fix Can't Connect to Proxy Server Issue on Windows 10 · Method 1: Checking if your Connection is Stable · Method...
Read more >
Stuck with Proxy Error? Ways to Solve It - Smartproxy
Here's the way: Applications > System Preferences > Network > Advanced > Proxies. There you can check if you selected the right proxies....
Read more >
Websites don't load - troubleshoot and fix error messages
Click Settings…. The Connection Settings dialog will open. Change your proxy settings: If you don't connect to the Internet through a proxy (or...
Read more >
Page not loading with proxy but works without - Stack Overflow
If I don't use the proxy the page loads just fine. My code looks like the following. public static void main (String[] args)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found