[1.7.x] Restored Python 2 compatibility.

Backport of ee51ab9d232e52d17cd5ad32e230fd715cffe638 from master.