Fix the NoneType error during iteration when the pycap instance is None