Check for basestring, not just str

Fixes #2071

This provides consistent behaviour across Python 2 & 3.