Avoiding the FDSN Exception error message

Hi,
Every now and again I get an error message saying “No FDSN service could be discovered at …”. I usually just rerun my script and it works fine.

What I’m attempting to do is create a while not: loop for this error, so I only have to run the script once. The problem is I don’t know what type of error this is. I’ve written what I have at the moment below. Any help would be appreciated.

Cheers,
Alex

host = "RASPISHAKE"
client = ""
    while not client:
        try:
            client = Client(host)
        except ValueError:
            print("ValueError has occured")
            print("Check variable 'host' to confirm client name")
            quit()
        except IOError:
            print("I/O Error. Rerunning")
            continue
        break

Hello Alex,

Yes, I can understand why you would do that, it would save many restarting problems with a constant live stream access.

I think I managed to recreate your situation with my code. In this case the "No FDSN service could be discovered at …” error that you get is an Exception Error.

So, your code should become:

host = "RASPISHAKE"
client = ""
    while not client:
        try:
            client = Client(host)
        except Exception as e: 
#doing this would transfer the entire exception name to a variable, you can use it or not at your leisure
            print("ExceptionError has occured")
            print(str(e))
#this prints out the name of the error, if you want it for further verification or debugging
            print("Check variable 'host' to confirm client name")
            quit()
        except IOError:
            print("I/O Error. Rerunning")
            continue
        break

If you need further help feel free to ask more questions.

1 Like

Hi Stormchaser,

Worked perfectly, thank you! :smile: I’ve also added an attempt limiter using an if loop to stop an infinite number of errors coming onto the screen. The way I tested the Exception error (now I know the name) was by turning the internet off and running the script, and that produced an infinite loop.

Thanks again,
Alex

3 Likes

Hello Alex,

Glad to hear that it worked, you’re welcome! Yes, I was actually writing about that when I saw your answer, a limiter was needed to avoid the infinite without manually stopping it every time.

I tested it by removing a letter from the FSDN address, the important thing was that it didn’t find the source data in the end, but glad that we covered two different cases.

No worries!

2 Likes