LLI Wiki — My Digital Knowledge Base

Python: catching exceptions and fixing "undefined symbol: XML_SetHashSalt"

except syntax with a tuple and exception instance, and a workaround for the XML_SetHashSalt error using LD_LIBRARY_PATH.

Two Python memos: catching an exception to get more details, and fixing the undefined symbol: XML_SetHashSalt error.

Catching several exceptions and reading the error

An except clause accepts a tuple of exception types:

except (IOError, ValueError):

You can also grab the exception instance to print more details (Python 2 syntax, as in the original note):

try:
   fichier = open('foo.txt')
except IOError, e:
   print e

In Python 3, the equivalent syntax is except IOError as e: and print(e).

Error "undefined symbol: XML_SetHashSalt"

This error usually appears when Python loads a different libexpat than the one it expects. The fix noted is to make the loader look in the system libraries first:

export LD_LIBRARY_PATH=/lib64/:${LD_LIBRARY_PATH}
Mastodon LLIMastodon SocialFosstodon