Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: the JSON object must be str, not 'bytes' #13

Closed
runander opened this issue Jun 3, 2018 · 2 comments
Closed

TypeError: the JSON object must be str, not 'bytes' #13

runander opened this issue Jun 3, 2018 · 2 comments

Comments

@runander
Copy link

runander commented Jun 3, 2018

当我运行程序时候,总是出错。
with gzip.open(data_path, 'rb') as f:
data = json.loads(f.read())
return data
问题出现在这里,json接收str类型,gzip读取后是其他类型,尝试过类型转换,但是也没有成功,有没有解决办法。

@runander
Copy link
Author

runander commented Jun 11, 2018

自己解决了,查询gzip使用方法,https://docs.python.org/3/library/gzip.html, 如果想要返回为str类型,需要将with gzip.open(data_path, 'rb') as f中的'rb'改变成‘rt’。

@Lireanstar
Copy link

请问下,问改写了'rt'然后JSON文件出现如下错误,请问你有没有遇到类似错误呢?
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants