jazzband / tablib

Python Module for Tabular Datasets in XLS, CSV, JSON, YAML, &c.
https://tablib.readthedocs.io/
MIT License
4.59k stars 590 forks source link

python3-related? TypeError: 'encoding' is an invalid keyword argument for this function #452

Closed molecular closed 4 years ago

molecular commented 4 years ago

Hi,

during a python3 update orgy I ran across the following problem:

exception with type  <class 'TypeError'>  and args ("'encoding' is an invalid keyword argument for this function",) occurred when reading Filelist
Traceback (most recent call last):
  File "/home/nick/daisy/rs/plan/management/commands/import_gruppen.py", line 67, in handle
    dataset = tablib.import_set(open(file).read(), format="csv", delimiter=';', lineterminator='\n', encoding='utf-8')
  File "/home/nick/daisy/venv3/lib/python3.6/site-packages/tablib/core.py", line 916, in import_set
    return Dataset().load(normalize_input(stream), format, **kwargs)
  File "/home/nick/daisy/venv3/lib/python3.6/site-packages/tablib/core.py", line 422, in load
    fmt.import_set(self, stream, **kwargs)
  File "/home/nick/daisy/venv3/lib/python3.6/site-packages/tablib/formats/_csv.py", line 43, in import_set
    rows = csv.reader(in_stream, **kwargs)
TypeError: 'encoding' is an invalid keyword argument for this function

(this occurs with tablib 1.0.0 and also with 0.13.0)

not sure how to solve this. Maybe someone can help me?

molecular commented 4 years ago

after reading some docs I changes my import_set call from

dataset = tablib.import_set(open(file).read(), format="csv", delimiter=';', lineterminator='\n', encoding='utf-8') to

dataset = tablib.import_set(open(file, encoding='utf-8').read(), format="csv", delimiter=';', lineterminator='\n')

I'm not sure this is the correct way to specify file encoding?

claudep commented 4 years ago

Absolutely, encoding is a parameter of reading the (text) file, and the csv module expects text properly decoded.

molecular commented 4 years ago

makes sense. It worked like I did it previously with python2 and earlier version, though.