Search code examples
python-3.xquandl

Python 3.5 - Quandl error handling


Trying to figure out how to handle the error:

quandl.errors.quandl_error.NotFoundError: (Status 404) (Quandl Error QECx02) You have submitted an incorrect Quandl code. Please check your Quandl codes and try again.

Here's a snippet of the code that I would want the exception on:

            source = Q.get(query_site, authtoken=secret)
            df = df.join(source, how='outer')

I would want to break out if I get the error. What would be with my except statement? I tried NotFoundError but it did not seem to work.


Solution

  • Handling the NotFoundError

    from quandl.errors.quandl_error import NotFoundError
    
    try:
        source = Q.get(query_site, authtoken=secret)
        df = df.join(source, how='outer')
    except NotFoundError as e:
        print('error: {} '.format(str(e)))