fix bug 1037537 - encode utf-8 properly, and remove NULL characters whic...

...h postgres will not allow to be imported into TEXT NOT NULL columns
Oh and this is to handle ```int```s, since they don't have an ```.encode()```:
```
>>> i = 123
>>> i.encode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'int' object has no attribute 'encode'
```