datafreeze
datafreeze copied to clipboard
Freeze using prescribed fileobj mode 'wb' raises TypeError
Following the example code for using a fileobj parameter at URL https://dataset.readthedocs.io/en/latest/_modules/datafreeze/app.html#freeze, I get the following exception:
>>> result = db['auth_user']
>>> fh = open('/dev/null', 'wb')
>>> datafreeze.freeze(result, format='json', fileobj=fh)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/opt/gss/venvs/3.6/lib64/python3.6/site-packages/datafreeze/app.py", line 124, in freeze
return freeze_export(Export({}, kw), result=records)
File "/opt/gss/venvs/3.6/lib64/python3.6/site-packages/datafreeze/app.py", line 136, in freeze_export
serializer.serialize()
File "/opt/gss/venvs/3.6/lib64/python3.6/site-packages/datafreeze/format/common.py", line 93, in serialize
self.close()
File "/opt/gss/venvs/3.6/lib64/python3.6/site-packages/datafreeze/format/fjson.py", line 61, in close
fh.write(data)
TypeError: a bytes-like object is required, not 'str'
Should the fileobj be mode 'wt' instead? Initially I was using an io.BytesIO, as would be appropriate for mode 'wb' and it produced the same exception, however a io.StringIO object worked. Appears a (one letter) documentation fix is needed. Thanks for such a great module.
edit: spellig
Ok, looks like this is a Python 3 issue. Are you interested in helping with a PR?
Yes, Python 3.6. Sure, what I can do to help.