Handling errors in potentially incomplete responses I am using the library geoip2 to get Geolocation of many IP adderesses

&quot;&quot;&quot;
input:
        str:   IP
output ordered list: 
    [0] str:   City, State, Country
    [1] tuple: (Lat; Log)
    [2] str:   Postal
&quot;&quot;&quot;

for i in pd.unique(df_to_print['requesterIp']):
    res = reader.city(i)
    # NOTE: Second snippet is added here
    myDict[i] = [res.city.names['en'] + &quot;, &quot; + res.subdivisions[0].names['en'] + &quot;, &quot; +  res.country.names['en'],(res.location.latitude, res.location.longitude), res.postal.code]

# output:  ['Calgary, Alberta, Canada', (50.9909, -113.9632), 'T2C']

Sometimes the response, which is in JSON, is missing some fields. This causes a exception.
Here is my proposed &quot;fix&quot;, the code works as intended, but looks sinful
try:
    city = res.city.names['en']
except:
    city = &quot;-1&quot; 

try:
    state = res.subdivisions[0].names['en']
except:
    state = &quot;-1&quot; 
    
try:
    country =  res.country.names['en']
except:
    country =  &quot;-1&quot;
    
try:
    cord = (res.location.latitude, res.location.longitude)
except:
    cord = (-1, -1)

postal = res.postal.code if res.postal.code is not None else -1


print([city + &quot;, &quot; + state + &quot;, &quot; +  country, cord, postal]) 
# output: ['-1, -1, China', (34.7725, 113.7266), -1]

What can I do to make my code more professional and efficient?
(this will run for apx. 100K unique IPs, several times a hour; DB is local)
Some suggestions:

Don't use exceptions for flow control unless you have to for TOCTOU or other reasons. &quot;Tell, don't ask&quot; is a useful guideline when requesting something from a piece of state the current code has no control over, but it's not a law. In your code there is no chance of res.country.names changing while running res.country.names.get('en', &quot;-1&quot;), and that is much clearer than using exception handling to set a default.
You almost always want to catch specific exceptions.
When retrieving values from a dict you can use my_dict.get(&quot;key&quot;, default) to get a default value if the key does not exist.
Use f-strings rather than + to create formatted strings.