seabird
seabird copied to clipboard
encoding error when reading the example file
Hi!
Im actually enrolled on a task that involve me to use the QC seabird python package. I actually been following the notebooks examples, but on the first first step i found a error (spooky error).
I guess that its something related python encoding, inclusive some pip packages that i had been installed.
Some help would be appreciated :D
My code (using jupyter too):
%matplotlib inline
from seabird.cnv import fCNV
# Reading the CNV file (8038)
#profile = fCNV('S8038_2021_01_13_M1.cnv')
# Reading the example file
profile = fCNV('dPIRX003.cnv')
The error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-3f5cca2014d9> in <module>
4
5 # Reading the example file
----> 6 profile = fCNV('dPIRX003.cnv')
~/.local/lib/python3.9/site-packages/seabird/cnv.py in __init__(self, filename, defaultsfile)
572
573 try:
--> 574 super(fCNV, self).__init__(text, defaults)
575 except CNVError as e:
576 if e.tag == 'noparsingrule':
~/.local/lib/python3.9/site-packages/seabird/cnv.py in __init__(self, raw_text, defaults)
56 self.attrs = {}
57 # ----
---> 58 self.rule, self.parsed = load_rule(self.raw_text)
59
60 if not hasattr(self, 'parsed'):
~/.local/lib/python3.9/site-packages/seabird/utils.py in load_rule(raw_text)
75 text = pkg_resources.resource_string(
76 __name__, os.path.join(rules_dir, rule_file))
---> 77 rule = json.loads(text.decode('utf-8'), encoding="utf-8")
78 # Should I load using codec, for UTF8?? Do I need it?
79 # f = codecs.open(rule_file, 'r', 'utf-8')
/usr/lib/python3.9/json/__init__.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
357 if parse_constant is not None:
358 kw['parse_constant'] = parse_constant
--> 359 return cls(**kw).decode(s)
TypeError: __init__() got an unexpected keyword argument 'encoding'
Actually using Python3.9, matplotlib and seabird last version.
Thanks a lot!
Hi, I see the same problem with python 3.9. The 'encoding' parameter seems to be deprecated in json.loads since python 3.9. From the Python 3.9 changes (https://docs.python.org/dev/whatsnew/3.9.html#removed): 'The encoding parameter of json.loads() has been removed. As of Python 3.1, it was deprecated and ignored; using it has emitted a DeprecationWarning since Python 3.8. (Contributed by Inada Naoki in bpo-39377)'
For your problem, I suggest using python 3.8 or earlier.
Yeah... Seems like that. I was trying to refactor the source code and removing the 'encoding' parameter but didnt work tbh...
I will try python 3.8.
Thank you!
Hm, removing the lines in the code is a good idea. I tried removing the encoding parameter from the code, and now it works for me on python 3.9.2. You have to remove it from 2 places though. Once in utils.py (line 77), and once in cnv.py (line 175). Cheers
Using Jupyter Notebooks, i forgot restart when changing that lines on the package... that's the reason because didn't work x)
However, i try your changes with a fresh install of the package and now works fine! Thank you!!
Having the same error; @jakobdoerr thanks for identifying the lines that need to be modified. Any plans to incorporate these changes into an updated release?