[1.7.x] Fixed the previous commit for Python3.

Backport of 4453c80634fb72b60e849480e52c06b570c696d5 from master.