Could you post a minimal, executable code snippet to reproduce the issue, please?
Based on the error message and the posted code snippet it’s a bit hard to give a proper debugging advice besides repeating the error message.