Previously I was using an older version (I believe it was either 2020 R2.4 or 2021 R1 but I can't remember). The issue then started while I was using the older version. We updated to the latest version hoping this might fix the issue, however it has not. The only thing which has changed after updating is the error that Python is reporting (presumably due to changes in the error handling for the updated the lumapi module). But the line at which the code is failing is still the same.