0

i am a little bit new to coding, but i am trying to get data stored in a json file by another script though it keeps on giving me errors This is my code

import requests

URL = "http://127.0.0.1:5000/predict"
TEST_AUDIO_FILE_PATH = "test/soma.wav"

if __name__ =="__main__":
    audio_file = open(TEST_AUDIO_FILE_PATH, "rb")
    values = {"file":(TEST_AUDIO_FILE_PATH, audio_file, "audio/wav")}
    response = requests.post(URL, files=values)
    data = response.json()

    print(f"Predicted keyword is: {data['keyword']}")

This is the error i keep on getting File "C:\Users\Tatooine\Desktop\FYP\client.py", line 11, in response.json()

File "C:\ProgramData\Anaconda3\lib\site-packages\requests\models.py", line 897, in json return complexjson.loads(self.text, **kwargs)

File "C:\ProgramData\Anaconda3\lib\json__init__.py", line 348, in loads return _default_decoder.decode(s)

File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end())

File "C:\ProgramData\Anaconda3\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting value

1 Answer 1

0

i think you should decode the data variable first data = response.decode()

then after you can convert it to a json object

import json 
data = json.loads(data)

then print

print(f"Predicted keyword is: {data['keyword']}")

please let me know, if this works for you

Sign up to request clarification or add additional context in comments.

1 Comment

i had tried this but it gives me an, AttributeError: 'Response' object has no attribute 'decode'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.