Handling Screener errors in a for loop

Hello! When using the Python api to loop through criteria to screen for companies, the api is kicking out errors in some passes. Do you have any advice on how to store these errors and/or supress/skip over them to speed the loop up? Below is the code. The error arises because for some countries and industry code combinations, zero companies come out of the screener. Thanks a lot for your help.

import refinitiv.data as rd
rd.open_session()

import pandas as pd

indcode = [52, 53, 54, 57]
region = ["ES","AD","SM"]
syntax = "SCREEN(U(IN(Equity(active,public,primary))), CURN=USD"
CATfields = ["TR.CommonName", "TR.HeadquartersCountry", "TR.HQCountryCode"]

dataCAT2 = []
for i in region:
for j in indcode:
dataCAT1 = rd.get_data(syntax + f", IN(TR.TRBCEconSectorCode,{j}), IN(TR.HQCountryCode,{i}))", CATfields)
dataCAT2.append(dataCAT1)
df1 = pd.concat(dataCAT2)

Best Answer

Answers

  • Thanks -- so I think this code is still working, based on what you're saying -- it's not stopping my Refinitiv query; it's just throwing an error on one iteration but is still giving me a result on the iterations that do work.