pyDataverse API simplejson.errors.JSONDecodeError

88 views
Skip to first unread message

Lily Falk

unread,
Aug 9, 2022, 4:18:08 PM8/9/22
to Dataverse Users Community
I have sporadically hit:
simplejson.errors.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

when using the Dataverse API using the pyDataverse package and modified .json files from the user guide

Has anyone else experienced this issue and know the cause? As far as I can tell it is not specific to a data type/file, and I believe it is happening on the dataverse side. 

Thanks!

Philip Durbin

unread,
Aug 9, 2022, 4:31:18 PM8/9/22
to dataverse...@googlegroups.com
Hmm, I just ran checked both JSON files you linked to with jq:

cat dataset.json | jq .

cat dataverse.json | jq .

And they can be parsed just fine. Perhaps you could double-check your modified JSON files with jq or an online validator.

It's very strange that you're only seeing this sporadically. It looks like a parsing error. Have you tried your JSON files on https://demo.dataverse.org ? Are you able to share your JSON files? Have you tried using curl commands from the API Guide? Just some ideas. :)

Hope this helps,

Phil

--
You received this message because you are subscribed to the Google Groups "Dataverse Users Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-commu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dataverse-community/5d1e2f43-705b-405f-9d5e-6c534d036cbdn%40googlegroups.com.


--

Lily Falk

unread,
Aug 30, 2022, 5:50:39 PM8/30/22
to dataverse...@googlegroups.com
Thanks for the ideas, Phil! Yes, I guess it is a problem with my file in some way I am not sure of yet. The same function and JSON works for some of my datasets and fails on others... The JSON file I am currently using is the same as the sample linked. 

And yes, I have tried curl and tried on a demo collection I created...

The error I am currently encountering is just a key error:

ds_pid = resp.json()["data"]["persistentId"]

KeyError: 'data'


So it seems there is some trouble in grabbing the PID for some reason, sometimes..?


You received this message because you are subscribed to a topic in the Google Groups "Dataverse Users Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dataverse-community/R7iBYx1iswQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dataverse-commu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dataverse-community/CABbxx8FgQnbAAM05VYubdNgJi2GyVSaGWis6M8m3Rh7a8%2Bsm9A%40mail.gmail.com.

Philip Durbin

unread,
Aug 31, 2022, 3:37:30 PM8/31/22
to dataverse...@googlegroups.com
Hi Lily,

"data" is what the API shows on success (in the JSON response, I mean). On failure, instead of "data" you get "message" with the error message. (This is sort of a quirk of the API, sorry.)

My guess is that "KeyError" happens when the API is giving you an error. Before checking for "data", I'd suggest checking for a 200/OK response. If you don't get 200/OK, you should probably print out the JSON so you can see what the error is.

I hope this helps! Please feel free to pop in https://chat.dataverse.org if you have other questions.

Thanks,

Phil

Reply all
Reply to author
Forward
0 new messages