Python Forum
A lot of confusion and I can't seem to solve this issue
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A lot of confusion and I can't seem to solve this issue
#9
(Jul-24-2022, 07:24 PM)Calli Wrote: can we add an exception or??
Yes can do that(pass it out so loop will not stop) and can also set shorter time so it goes faster on timeout errors.
import requests

with open('ip_lst1.txt') as f:
    for ip in f:
        try:
            ip = ip.strip()
            print(ip)
            response = requests.get(f"http://{ip}:9200/_cat/indices", timeout=2)
            print(response.text.strip())
        except Exception as error:
            #print(error)
            pass
Output:
118.31.106.59 green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb 118.31.106.59 green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb 124.221.82.115 # error still continue 118.31.106.59 green open .geoip_databases vtWge-U1SLefV6CuavYxCQ 1 0 40 40 37.7mb 37.7mb 118.31.106.70 # error
rob101 likes this post
Reply


Messages In This Thread
RE: A lot of confusion and I can't seem to solve this issue - by snippsat - Jul-24-2022, 08:02 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020