helallao / perplexity-ai

Unofficial API Wrapper for Perplexity.ai + Account Generator
https://perplexity.ai
MIT License
285 stars 50 forks source link

static t token in websocket requests causing issues? #36

Closed jxng closed 8 months ago

jxng commented 9 months ago

I'm trying to use my own account, however I am not able to get past the first websocket request. I am very sure I have copied the cookies/headers correctly with this #4

I'm starting to suspect it could be the t parameter in the url.

In perplexity.py line 87 - self.t = format(random.getrandbits(32), '08x'), we're creating the t token as a random string of characters and we are using the same values for every websocket request we make.

This is not consistent the dynamic t tokens being generated as we observe the network packages back and forth on Chrome

Screen Shot 2024-01-23 at 7 23 09 pm

helallao commented 9 months ago

It's working on my pc. I don't know what is the problem but it doesn't look like because of "t token". You can change codes to fix the problem but it's working on my pc so i don't think this is the problem.

thanhtamns commented 9 months ago

Can you tell me your python version? I always have my problems when using multiple workflows. and even if I use the sample code and continuously change cookies/header but the value of self._last_answer is always None. image

This is my code for test: image

I discovered that the websocket thread always shuts down after 0.5 seconds Can you give me any information about python and your coding environment?

jxng commented 9 months ago

I can confirm that I am getting the same issue as the above

helallao commented 9 months ago

I'm using python 3.11.3 and everything is as default.

thanhtamns commented 9 months ago

I have tried everything, i installed on anaconda but it seems impossible. Can you move it to docker?

helallao commented 9 months ago

There will be no difference, it's not about codes. There must be something else. Add a print(message) to beginning of function on line 176 like this:

def on_message(self, ws, message):
    print(message)

Run the script and upload all output here. Maybe i can find the problem.

jxng commented 9 months ago

@helallao I should also mentioned that I noticed the web browser requests to perplexity are now v2.2, while our code only uses v2.1, so it could be another point of red flag to cloudflare

thedavidweng commented 9 months ago

I have tried everything, i installed on anaconda but it seems impossible. Can you move it to docker?

^^ A docker container would solve all the environment problems

thanhtamns commented 9 months ago

There will be no difference, it's not about codes. There must be something else. Add a print(message) to beginning of function on line 176 like this:

def on_message(self, ws, message):
    print(message)

Run the script and upload all output here. Maybe i can find the problem.

The problem lies in the websocket, the thread to start the websocket disconnects and stops itself right after it runs, so the message cannot be received. I think cloudfle's problem: image And after 0,5 second: image

helallao commented 9 months ago

Actually i don't have much experience with docker, so can't somebody else make a docker image with codes?