Set a default if key not in a dictionary, *or* value is None
for message in d.get('messages') or ():
    do_something()



get returns None by default for missing keys.
a or b evaluates to b when bool(a) == False. An empty list and None are examples of values that are false in a boolean context.
Note that you cannot use this trick if you intend to modify the possibly empty list that is already in the dict. I'm using () instead of [] to guard against such mistakes. Also, CPython caches the empty tuple, so using it is slightly faster than constructing an empty list.