Skip to content

JSONDecodeError: Extra data: line 1 column 61 (char 60) #5

@al-yakubovich

Description

@al-yakubovich

Hi. I am getting the following error:

JSONDecodeError: Extra data: line 1 column 61 (char 60)
Traceback:
File "C:\Users\AppData\Local\anaconda3\envs\py311_test\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
    exec(code, module.__dict__)
File "C:\Users\Desktop\GenAI\app\app2_test\interface.py", line 72, in <module>
    decoded_response = decode_response(response)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Desktop\GenAI\app\app2_test\interface.py", line 17, in decode_response
    return json.loads(response)
           ^^^^^^^^^^^^^^^^^^^^
File "C:\Users\AppData\Local\anaconda3\envs\py311_test\Lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\\AppData\Local\anaconda3\envs\py311_test\Lib\json\decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)

It looks like something wrong with decode_response function.

I changed it to:

def decode_response(response: str) -> dict:
    lines = response.splitlines()
    json_line = lines[0]  
    return json.loads(json_line)

and it started working for simple questions, but it fails for most questions (e.g. plot something)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions