You don't need three tostring method. This is only in sip v1 and qgis uses v2.  Make sure you call `import qgis` as there first thing you do in your script so that it sets the right api version.