Replace instances of basestring with six.string_types and convert an .iteritems to just .items.