nathanrchn / perplexityai

A python api to use perplexity.ai
183 stars 39 forks source link

WebSocketConnectionClosedException: socket is already closed #1

Open jxonly opened 1 year ago

jxonly commented 1 year ago

i followed the codes:

perplexity = Perplexity.Perplexity() answer = perplexity.search("What is the meaning of life?") print(answer.json_answer_text["answer"]) but i get this problem. i can visit the perplexity.ai website and i think its not the network error.

nathanrchn commented 1 year ago

I'm sorry, but everything is working normally for me. I fixed some issues recently, did you pull the new changes?

jxonly commented 1 year ago

I'm sorry, but everything is working normally for me. I fixed some issues recently, did you pull the new changes?

i tried the latest code, it still not work. The reason for the problem may be that I used a proxy server to access this website address but in the codes i did not use proxy.

ShaneOss commented 11 months ago

@jxonly you could add proxy servers like the following, but it may not work with websockets.

def init_session(self) -> Session:
    session: Session = Session()

    proxy_servers = {
       'http': 'http://proxy.sample.com:8080',
       'https': 'http://secureproxy.sample.com:8080',
    }
    session.proxies.update(proxy_servers)

    uuid: str = str(uuid4())
    session.get(url=f"https://www.perplexity.ai/search/{uuid}", headers=self.user_agent)
syntaxsurge commented 5 months ago

@jxonly you could add proxy servers like the following, but it may not work with websockets.

def init_session(self) -> Session:
    session: Session = Session()

    proxy_servers = {
       'http': 'http://proxy.sample.com:8080',
       'https': 'http://secureproxy.sample.com:8080',
    }
    session.proxies.update(proxy_servers)

    uuid: str = str(uuid4())
    session.get(url=f"https://www.perplexity.ai/search/{uuid}", headers=self.user_agent)

Ho to make proxies work in websockets? Without exporting the proxy as environment variable?