Backport 1.8 3701

Backport #3701 fixes for Python 3.4.