mangiucugna / json_repair

A python module to repair invalid JSON, commonly used to parse the output of LLMs
https://pypi.org/project/json-repair/
MIT License
826 stars 48 forks source link

getting '_io.TextIOWrapper' object has no attribute 'strip'. Not sure if i'm using it wrong or python version conflict #38

Closed Jaron123 closed 5 months ago

Jaron123 commented 5 months ago

When I try the example of:

import sys
import json_repair
from json_repair import repair_json

JSON_PATH = "/Path/To/JSON/File.txt"

print(sys.version)

try:
    file_descriptor = open(JSON_PATH, 'r')
except OSError:
    ...

try:
    with file_descriptor:
        decoded_object = json_repair.load(file_descriptor)
except Exception as e:
        print("Repairing logfile failed")
        print(f"An exception occurred: {e}")

I get returned:

3.9.2 (default, Feb 28 2021, 17:03:44) 
[GCC 10.2.1 20210110]
Repairing logfile failed
An exception occurred: '_io.TextIOWrapper' object has no attribute 'strip'

in this case the JSON file that is referenced with JSON_PATH is valid. I've also tried breaking it but I always get this exception. As you can see I'm running Python 3, not sure if that could cause the problem?

mangiucugna commented 5 months ago

Sorry, this is something dumb in the export of the functions. I am releasing a new version with the fix

Jaron123 commented 5 months ago

Thanks, it works like a charm now!