I am getting an error while reading JSON file using python's json module and I'm not able to understand what is wrong. Below are my files and code for your reference:
json.load(files_lst[1])
error:
AttributeError: 'str' object has no attribute 'read'
After reading several answers I also tried:
json.loads(files_lst[1])
but I get the following error:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
What is wrong here? Thanks a lot for your help
>>> files_lst
['All_Transcripts/x3021_10.50.48.111_04-04-2019.json',
'All_Transcripts/x5363_09.33.36.955_08-27-2019.mp3.json',
'All_Transcripts/x3580_11.35.53.462_05-13-2019.json',
'All_Transcripts/x4342_08.55.01.523_08-01-2019.json',
'All_Transcripts/x9496_15.26.32.382_05-21-2019.json',
'All_Transcripts/x5374_08.38.15.692_06-17-2019.json',
'All_Transcripts/x4342_13.43.57.128_03-21-2019.json']
json.load accepts an open file descriptor. So you should call it like this:
json.load(open(files_lst[1]))
json.loads accepts a json as a string. So you should call it like this:
json.loads(open(files_lst[1]).read())
Related
This is how the code is with all its quotation marks placed below
{"address":"abc123a0b123b123ab12345b1abcd12345d12a123","id":"12ab1234-12b1-12ab-1234-1ab12345abc1","version":3,"crypto":{"cipher":"abc-123-abc","cipherparams":{"iv":"ab1234abcd123a1bc12a123a1234b12"},
Ur json has invalid format. Try this resource for checking JSONs.
I am trying to read csv.deflate files from hdfs path and put them in dask dataframe. I tried read_csv and I am getting "UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9c in position 1: invalid start byte" error. Then, I set engine='python' and encoding='utf-8' but I am still getting the same error.
Perhaps the compression= keyword would help? How would you read this data locally with Pandas? I suspect that you need the same keyword arguments that you would need in that case.
I'm using discord.py to create a bot for my server. I'm following a tutorial made by Spyros, and I'm getting this error:
JSONDecodeError: Expecting value: line 1 column 1 (char 0)]
It's just an empty JSON file, just curly brackets with no data.
Anyone knows what I can do? I'll post more code if needed, thanks!
JSONDecode is expecting data and as you said, you are passing an empty JSON "file"
TypeError while loading the pickle file using pickle.load() in python3:jupyter notebook
with open("/home/amit/Downloads/may2_18_company_data_with_cluster.pickle","r",encoding='utf8') as f:
c = pickle.load(f) //this line shows an error
TypeError: a bytes-like object is required, not 'str'
Please help me to fix this on jupyter notebook with python3.
This is because pickle.load expects a binary type file as an argument, you need to specify this in the use of open by specifying rb for read binary instead of 'r' which reads as a string. Changing the code to:
with open("/home/amit/Downloads/may2_18_company_data_with_cluster.pickle","rb",encoding='utf8') as f:
c = pickle.load(f)
should solve this.
I'm using a program called Wrapper.py(this), but there's some type of error. Becouse it's Python, I've tried to found the error. As far as I know, the error is at that it tries to write & load some JSON, but it receives strings like this: "Közép-európai nyelvezet", or something like this. It causes UnicodeDecodeError:
>>>import json
>>>out={"a":"Közép-európai nyelvterület"}
>>>json.dumps(out)
Tracebank(the path, etc.)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x94 in position 1: Invalid start byte
Then I googled, & found that solution for encoding:
>>>a=json.dumps(out,ensure_ascii=False)
>>>a
'{"a":"K\x94z\x82p-eur\xarpai nyelvter\x81let"}'
Then I wanted to load it:
>>>json.loads(a)
Traceback, etc.
UnicodeDecodeError: 'utf8' codec can't decode byte 0x94 in position 1: Invalid start byte
>>>json.load(a,ensure_ascii=False)
Traceback
TypeError: __init__() got an unespected keyword argument: 'ensure_ascii'
How can I load my data back?
Thanks in advance for your help!
Use text instead of bytestrings.
out = {u"a":u"Közép-európai nyelvterület"}