Backport 1.7 3701

Backport #3701 fixes for Python 3.4.