ckan / ckanapi

A command line interface and Python module for accessing the CKAN Action API
Other
176 stars 74 forks source link

fix CLI output from API on Python 3 #123

Closed grahame closed 6 years ago

grahame commented 6 years ago

This patch fixes this error under Python 3. The patch functions under Python 2.

$ ckanapi action group_list -r https://data.bioplatforms.com
Traceback (most recent call last):
  File "/home/gbowland/.virtual/bpa-ingest/bin/ckanapi", line 11, in <module>
    load_entry_point('ckanapi==4.0', 'console_scripts', 'ckanapi')()
  File "/home/gbowland/.virtual/bpa-ingest/lib/python3.5/site-packages/ckanapi/cli/main.py", line 110, in main
    sys.stdout.write(r)
TypeError: write() argument must be str, not bytes
wardi commented 6 years ago

no, you can't write unicode to sys.stdout in python2. Also if you're going to run the CLI in Python 3 you'll need to warn the user that the -c option won't work because ckan itself can't run in Python 3 yet

wardi commented 6 years ago

https://github.com/ckan/ckanapi/blob/master/ckanapi/cli/dump.py#L34 works as an object that you can write bytes to in python 2 and 3. You could make that change instead.

wardi commented 6 years ago

duplicate of #96

grahame commented 6 years ago

OK, I'll close in favour of #96. Thanks for reviewing.