0

I have a python script and I am using a function from a library where an error is generated for some of the inputs to the function: (Error 200, reqID #####: ....). If an error is generated, then I would like the I would like the script to omit the entry and continue.

I am wondering how to use try - except to catch the error. My script looks as follows:

try:
    contracts = ib.qualifyContracts(*contracts)
except ???:
    pass



Error 200, reqId 18929: ...
Error 200, reqId 18928: ...

I've tried inserting Error 200 (both with and without quotation) after the except phrase but the errors are not being caught. Any suggestions are appreciated.

Thanks.

EDIT:

I believe the library is library is just printing error messages. Errors look as follows below.

Error 200, reqId 8: No security definition has been found for the request, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20220921', strike=85.0, right='P', exchange='SMART', tradingClass='SPY')

Error 200, reqId 9: No security definition has been found for the request, contract: Option(symbol='SPY', lastTradeDateOrContractMonth='20220921', strike=90.0, right='P', exchange='SMART', tradingClass='SPY')
Alexander
  • 13
  • 6
  • Is the library actually raising exceptions or simply printing error messages? – saquintes Sep 21 '22 at 15:57
  • Can you post the full output that includes the error message? – JRose Sep 21 '22 at 16:03
  • I believe the library is printing error messages - is a try - except phrase not used for this? – Alexander Sep 21 '22 at 16:08
  • No, only when the library throws a python exception https://docs.python.org/3/tutorial/errors.html#exceptions can you then use an `except` block. If they are just printing errors you will need to take another approach. – JRose Sep 21 '22 at 16:10

0 Answers0