ckan / ckanapi

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

Error handling problems #209

Open pdelboca opened 11 months ago

pdelboca commented 11 months ago

Note: I'm running on Python 3.11

I'm facing issues when the package is trying to print to stderr (error logging).

Traceback (most recent call last):
  File "/home/pdelboca/Repos/ckanapi/.venv/bin/ckanapi", line 33, in <module>
    sys.exit(load_entry_point('ckanapi', 'console_scripts', 'ckanapi')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pdelboca/Repos/ckanapi/ckanapi/cli/main.py", line 156, in main
    return dump_things(ckan, thing[0], arguments)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pdelboca/Repos/ckanapi/ckanapi/cli/dump.py", line 110, in dump_things
    create_datapackage(record, datapackages_path, stderr, apikey)
  File "/home/pdelboca/Repos/ckanapi/ckanapi/datapackage.py", line 72, in create_datapackage
    create_resource(resource, filename, datapackage_dir, stderr, apikey)
  File "/home/pdelboca/Repos/ckanapi/ckanapi/datapackage.py", line 36, in create_resource
    stderr.write('URL {url} refused connection. The resource will not be downloaded\n'.format(url=resource['url']))
TypeError: a bytes-like object is required, not 'str'

It looks like the way we are trying to log things is not working properly. Also, we are trying to log normal workflow to the stderr output. Why is that?

            if not arguments['--quiet']:
                stderr.write('{0} {1} {2} {3} {4}\n'.format(
                    finished,
                    job_ids,
                    next(stats),
                    error,
                    record.get('name', '') if record else '',
                    ).encode('utf-8'))