helallao / perplexity-ai

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

Would it be possible to automatically update the header/cookies via Selenium WebDriver? #2

Closed Dima-369 closed 1 year ago

Dima-369 commented 1 year ago

First of all, thanks for this. This works quite well, but I often get the error that the tokens are expired. Is there a way to also automate that? The user still has to manually bypass Cloudflare with clicks, but it would make updating the tokens a lot easier.

helallao commented 1 year ago

it's possible but an easier way is that creating multiple accounts before your tokens get expired, so you will still be connected to them via websocket connections, even your tokens get expired.

Dima-369 commented 1 year ago

Ah, I understand now. I modified perplexity.py slightly to always exit after outputting the answer since I rarely run it and I usually only need a single answer when I invoke it from an external application.

By exiting, the websocket connection is simply not kept alive and I can't benefit from that. I also did not fill in emailnator_headers and emailnator_cookies. I suppose that is the issue for me here.

bacladjan-corp commented 1 year ago

could you please share the modified code if you don't mind?

Dima-369 commented 1 year ago

could you please share the modified code if you don't mind?

I just checked again and I, in fact, did not modify perplexity.py, but I close the websocket after .search() like this:

print(perplexity_cli.search('Your query here', mode='copilot', focus='internet'))
perplexity_cli.ws.close()

Then the script exits after answering.

bacladjan-corp commented 1 year ago

thank you very much, and as I understand I will have to update the cookie list sometimes ?

Dima-369 commented 1 year ago

thank you very much, and as I understand I will have to update the cookie list sometimes ?

Yes, study the README, it has all the info.