Fixed #22017 -- Prevented RuntimeError on Python 3

Refs #21049. Thanks quinox for the report.