API search() method fails silently for both anonymous and authenticated sessions #70

Open
opened 2025-09-18 14:47:56 -04:00 by agielweb · 2 comments
agielweb commented 2025-09-18 14:47:56 -04:00 (Migrated from github.com)

Bug Description

The perplexity.Client.search() method is currently non-functional. For both anonymous and authenticated (via create_account) sessions, the method returns None when stream=False or an empty generator when stream=True.

This appears to be caused by server-side changes at Perplexity that block the POST request to https://www.perplexity.ai/rest/sse/perplexity_ask. The request does not raise an exception but returns an empty response body, causing the iter_lines loop in the search method to yield no data.

Steps to Reproduce

  1. Anonymous search (fails):

    import perplexity
    cli = perplexity.Client()
    response = cli.search("hello")
    print(response) # Output: None
    
  2. Authenticated search (also fails):

    • Get fresh cookies from emailnator.com.
    • Run the following script:
    import perplexity
    
    emailnator_cookies = { ... } # Paste fresh cookies here
    
    cli = perplexity.Client()
    cli.create_account(emailnator_cookies) # This part now works after fixing the regex
    
    # The search call fails silently
    response = cli.search("hello", mode="pro") 
    print(response) # Output: None
    

Expected Behavior

The search() method should return a dictionary containing the search results from Perplexity.

Actual Behavior

The search() method returns None because the underlying request to perplexity_ask receives no data from the server, likely due to being blocked by anti-bot measures.

Conclusion

The library appears to be outdated and requires an update to its search method to align with Perplexity's current API protection mechanisms. The request fingerprint or payload for perplexity_ask likely needs to be updated to mimic a legitimate browser request more closely.

### Bug Description The `perplexity.Client.search()` method is currently non-functional. For both anonymous and authenticated (via `create_account`) sessions, the method returns `None` when `stream=False` or an empty generator when `stream=True`. This appears to be caused by server-side changes at Perplexity that block the `POST` request to `https://www.perplexity.ai/rest/sse/perplexity_ask`. The request does not raise an exception but returns an empty response body, causing the `iter_lines` loop in the `search` method to yield no data. ### Steps to Reproduce 1. **Anonymous search (fails):** ```python import perplexity cli = perplexity.Client() response = cli.search("hello") print(response) # Output: None ``` 2. **Authenticated search (also fails):** - Get fresh cookies from `emailnator.com`. - Run the following script: ```python import perplexity emailnator_cookies = { ... } # Paste fresh cookies here cli = perplexity.Client() cli.create_account(emailnator_cookies) # This part now works after fixing the regex # The search call fails silently response = cli.search("hello", mode="pro") print(response) # Output: None ``` ### Expected Behavior The `search()` method should return a dictionary containing the search results from Perplexity. ### Actual Behavior The `search()` method returns `None` because the underlying request to `perplexity_ask` receives no data from the server, likely due to being blocked by anti-bot measures. ### Conclusion The library appears to be outdated and requires an update to its `search` method to align with Perplexity's current API protection mechanisms. The request fingerprint or payload for `perplexity_ask` likely needs to be updated to mimic a legitimate browser request more closely.
mp3-10 commented 2025-10-03 09:06:23 -04:00 (Migrated from github.com)

As I tested, returned status is 200, headers looks good, but body/content is empty

As I tested, returned status is 200, headers looks good, but body/content is empty
lifanwar commented 2025-11-24 13:09:56 -05:00 (Migrated from github.com)

I can confirm experiencing the exact same issue. The problem occurs specifically when running from my Ubuntu server (both direct execution and via Docker Compose), while it works perfectly fine on my local machine.

Environment Details

  • Server: Ubuntu with same codebase
  • Result: HTTP 403 error from /rest/sse/perplexity_ask endpoint
  • Local machine: No issues whatsoever

Troubleshooting Attempts

I tried manually accessing Perplexity via browser using my server's IP address to pass Cloudflare challenge, but even after manual verification, the wrapper still returns 403 when executed from the same server IP.

Sample Error Log

[CLI-LOG] POST done, status: 403
[CLI-LOG] ERROR HTTP: 403 preview: ''
Answer: Error: No response from API

Root Cause Analysis

Since curl_cffi is already implemented in the code, the issue isn't TLS fingerprinting. This appears to be datacenter/server IP blocking. Cloudflare employs multiple detection layers:

  1. IP reputation blocking - Server/datacenter IPs are often automatically blacklisted
  2. ASN-based filtering - Hosting provider IP ranges trigger higher scrutiny
  3. Geographic restrictions - Non-residential IPs face stricter validation

The same request with identical fingerprints succeeds from residential IPs but fails from hosting providers. This explains why local machine works but server deployment doesn't.

Potential Solutions

  1. Use residential proxy rotation
  2. Implement retry logic with IP rotation for 403 errors

Has anyone tested with residential proxies or found workarounds for datacenter IP blocking?

I can confirm experiencing the exact same issue. The problem occurs specifically when running from my Ubuntu server (both direct execution and via Docker Compose), while it works perfectly fine on my local machine. ### Environment Details - **Server:** Ubuntu with same codebase - **Result:** HTTP 403 error from `/rest/sse/perplexity_ask` endpoint - **Local machine:** No issues whatsoever ### Troubleshooting Attempts I tried manually accessing Perplexity via browser using my server's IP address to pass Cloudflare challenge, but even after manual verification, the wrapper still returns 403 when executed from the same server IP. ### Sample Error Log ```[CLI-LOG] POST /rest/sse/perplexity_ask ... [CLI-LOG] POST done, status: 403 [CLI-LOG] ERROR HTTP: 403 preview: '' Answer: Error: No response from API ``` ### Root Cause Analysis Since `curl_cffi` is already implemented in the code, the issue isn't TLS fingerprinting. This appears to be **datacenter/server IP blocking**. Cloudflare employs multiple detection layers: 1. **IP reputation blocking** - Server/datacenter IPs are often automatically blacklisted 2. **ASN-based filtering** - Hosting provider IP ranges trigger higher scrutiny 3. **Geographic restrictions** - Non-residential IPs face stricter validation The same request with identical fingerprints succeeds from residential IPs but fails from hosting providers. This explains why local machine works but server deployment doesn't. ### Potential Solutions 1. Use residential proxy rotation 2. Implement retry logic with IP rotation for 403 errors Has anyone tested with residential proxies or found workarounds for datacenter IP blocking?
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#70
No description provided.