DominikBuchner / BOLDigger-commandline

BOLDigger as a commandline tool
MIT License
8 stars 0 forks source link

Error with json.decoder during API verification #13

Closed naurasd closed 2 months ago

naurasd commented 6 months ago

Hi,

I am using the latest version 2.2.1:

I am getting the following error during API verificaiton, seems to be something with json.decoder:

Calling API: 99%|█████████▊| 147/149 [01:55<00:00, 6.48it/s]/home/naurasd/.local/lib/python3.9/site-packages/boldigger /api_verification.py:73: FutureWarning: Series.getitem treating keys as positions is deprecated. In a future version , integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use ser.iloc[pos] bold_id = r.loc[r["taxonomicidentification"] == most_common].iloc[0][0] Calling API: 100%|██████████| 149/149 [01:58<00:00, 1.25it/s] Traceback (most recent call last): File "/home/naurasd/.local/bin/boldigger-cline", line 8, in sys.exit(main()) File "/home/naurasd/.local/lib/python3.9/site-packages/boldigger_cline/main.py", line 130, in main api_verification.main(args.xlsx_path, args.fasta_path) File "/home/naurasd/.local/lib/python3.9/site-packages/boldigger_cline/api_verification.py", line 56, in main corrected_data = refresh_data(result, raw_data, data_to_check, session) File "/home/naurasd/.local/lib/python3.9/site-packages/boldigger/api_verification.py", line 135, in refresh_data r = json.loads(r.text)["bold_records"]["records"] File "/sw/EasyBuild/rackham/software/Python/3.9.6-GCCcore-11.2.0/lib/python3.9/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/sw/EasyBuild/rackham/software/Python/3.9.6-GCCcore-11.2.0/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/sw/EasyBuild/rackham/software/Python/3.9.6-GCCcore-11.2.0/lib/python3.9/json/decoder.py", line 355, in raw_deco de raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Any idea whats going on here?

Thanks

DominikBuchner commented 2 months ago

This looks like either a malformed response by the API (happens more often than you think), or the XML that is returned is not read correctly. As you may be able to spot at that point in time I was not yet familiar with parsing XML and used the JSON parser. With BOLDigger2 I parse the XML with an actual XML parser and error like this should no longer happen! €: And the API correction is no longer needed.