File "C:\Users\ms\ppenv\Lib\site-packages\perplexity\client.py", line 206, in search #61

Open
opened 2025-06-29 07:49:26 -04:00 by geohk · 5 comments
geohk commented 2025-06-29 07:49:26 -04:00 (Migrated from github.com)

got below error just for today ? anyone met the same?

Traceback (most recent call last):
File "C:\Users\ms\ppapi.py", line 30, in
resp = perplexity_cli.search('tsla news today', mode='reasoning', model='o3-mini', sources=['web'], stream=False, language='en-US', follow_up=None, incognito=False)
File "C:\Users\ms\ppenv\Lib\site-packages\perplexity\client.py", line 206, in search
content_json['text'] = json.loads(content_json['text'])

got below error just for today ? anyone met the same? Traceback (most recent call last): File "C:\Users\ms\ppapi.py", line 30, in <module> resp = perplexity_cli.search('tsla news today', mode='reasoning', model='o3-mini', sources=['web'], stream=False, language='en-US', follow_up=None, incognito=False) File "C:\Users\ms\ppenv\Lib\site-packages\perplexity\client.py", line 206, in search content_json['text'] = json.loads(content_json['text'])
YoannDev90 commented 2025-06-29 11:31:23 -04:00 (Migrated from github.com)

Looks like Perplexity just updated the response format

Looks like Perplexity just updated the response format
YoannDev90 commented 2025-06-29 11:33:03 -04:00 (Migrated from github.com)

@geohk can you try to add a print statement before this line on client.py ?

@geohk can you try to add a print statement before this line on client.py ?
2-man commented 2025-07-06 17:47:08 -04:00 (Migrated from github.com)

change function stream_response in client.py to

        async def stream_response(resp):
            full_answer = None
            async for chunk in resp.aiter_lines(delimiter=b'\r\n\r\n'):
                content = chunk.decode('utf-8')
                if content.startswith('event: message\r\n'):
                    content_json = json.loads(content[len('event: message\r\ndata: '):])
                    for block in content_json.get('blocks', []):
                        if block.get('intended_usage') == 'ask_text':
                            markdown = block.get('markdown_block', {})
                            if markdown.get('progress') == 'DONE' and 'answer' in markdown:
                                full_answer = markdown['answer']
                elif content.startswith('event: end_of_stream\r\n'):
                    break
            if full_answer is not None:
                return full_answer
            else:
                print("No full response.")
                return None
        
        if stream:
            return await stream_response(resp)
        
        async for chunk in resp.aiter_lines(delimiter=b'\r\n\r\n'):
            content = chunk.decode('utf-8')
            
            if content.startswith('event: message\r\n'):
                content_json = json.loads(content[len('event: message\r\ndata: '):])
                content_json['text'] = json.loads(content_json['text'])
                
                chunks.append(content_json)
            
            elif content.startswith('event: end_of_stream\r\n'):
                return chunks[-1]

example of usage:

    perplexity_cli = await perplexity_async.Client(perplexity_cookies)
    full_answer = await perplexity_cli.search(
        'Your question',
        mode='pro',
        model='gpt-4o',
        sources=['web'],
        files={},
        stream=True,
        language='en-US',
        follow_up=None,
        incognito=False
    )
    print(full_answer)
    
    # dodawanie plikow: files={'myfile.txt': open('file.txt').read()}

asyncio.run(test())```
change function stream_response in client.py to ``` async def stream_response(resp): full_answer = None async for chunk in resp.aiter_lines(delimiter=b'\r\n\r\n'): content = chunk.decode('utf-8') if content.startswith('event: message\r\n'): content_json = json.loads(content[len('event: message\r\ndata: '):]) for block in content_json.get('blocks', []): if block.get('intended_usage') == 'ask_text': markdown = block.get('markdown_block', {}) if markdown.get('progress') == 'DONE' and 'answer' in markdown: full_answer = markdown['answer'] elif content.startswith('event: end_of_stream\r\n'): break if full_answer is not None: return full_answer else: print("No full response.") return None if stream: return await stream_response(resp) async for chunk in resp.aiter_lines(delimiter=b'\r\n\r\n'): content = chunk.decode('utf-8') if content.startswith('event: message\r\n'): content_json = json.loads(content[len('event: message\r\ndata: '):]) content_json['text'] = json.loads(content_json['text']) chunks.append(content_json) elif content.startswith('event: end_of_stream\r\n'): return chunks[-1] ``` example of usage: ```async def test(): perplexity_cli = await perplexity_async.Client(perplexity_cookies) full_answer = await perplexity_cli.search( 'Your question', mode='pro', model='gpt-4o', sources=['web'], files={}, stream=True, language='en-US', follow_up=None, incognito=False ) print(full_answer) # dodawanie plikow: files={'myfile.txt': open('file.txt').read()} asyncio.run(test())```
dearrevils commented 2025-09-03 09:56:31 -04:00 (Migrated from github.com)

i have fixed this issue + added new model support
go to pull request i added my contribution there

i have fixed this issue + added new model support go to pull request i added my contribution there
amansinna commented 2025-10-17 13:50:05 -04:00 (Migrated from github.com)

I am also facing the same issue. Any fix yet ?

File "C:\Users\Documents\projects\perplexity.venv\Lib\site-packages\perplexity_async\client.py", line 231, in search
content_json['text'] = json.loads(content_json['text'])
~~~~~~~~~~~~^^^^^^^^
KeyError: 'text'

I am also facing the same issue. Any fix yet ? File "C:\Users\\Documents\projects\perplexity\.venv\Lib\site-packages\perplexity_async\client.py", line 231, in search content_json['text'] = json.loads(content_json['text']) ~~~~~~~~~~~~^^^^^^^^ KeyError: 'text'
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
helallao/perplexity-ai#61
No description provided.