Fix Python3 Support

This PR does 2 things.

1. better handle str type checking to prevent errors in python3
2. removes a .encode call that was causing postgresql syntax errors.