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

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) #58

Open
AtulRajVAASITS opened this issue Apr 25, 2024 · 3 comments

Comments

@AtulRajVAASITS
Copy link

👦: hai
Traceback (most recent call last):
File "d:\Working on\ml\research\test.py", line 956, in
for a in Perplexity().generate_answer(prompt):
^^^^^^^^^^^^
File "d:\Working on\ml\research\research\Lib\site-packages\perplexityai_init_.py", line 25, in init
self.sid = loads(response)["sid"]
^^^^^^^^^^^^^^^
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alok.r\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\alok.r\AppData\Local\Programs\Python\Python311\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@AtulRajVAASITS
Copy link
Author

I have taken the latest version

@QZepHyr
Copy link

QZepHyr commented Aug 28, 2024

me too

@BJarboe
Copy link

BJarboe commented Nov 7, 2024

I have a workaround but kept running into issues. Feel free to troubleshoot further, but I think I'm just gonna look for alternatives to perplexity with how many problems keep appearing.

Some necessary dependencies:

pip install selenium undetected_chromedriver setuptools

In perplexityai\init.py:

from json import loads, dumps, JSONDecodeError
from selenium import webdriver
import undetected_chromedriver as uc
import re

Same file in Perplexity's class constructor. Replace the response = (... line with this code block

        driver = uc.Chrome()
        driver.get(f"https://www.perplexity.ai/socket.io/?EIO=4&transport=polling&t={self.t}")
        response = driver.page_source
        json_match = re.search(r'0(\{.*\})', response)
        if json_match:
            json_data = json_match.group(1)  # The JSON string we need
            try:
                parsed_data = loads(json_data)  # Parse JSON data
                sid = parsed_data["sid"]  # Access sid field
            except JSONDecodeError as e:
                print("Failed to parse JSON:", e)
        else:
            print("No JSON data found in response")
        driver.quit()

Basically it uses a headless browser to pass some security checks then filters the pulled html for the actual JSON with regex.
Again it gets around this issue but another one comes up when asserting a POST request.
Happy Troubleshooting :^)

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