poe-api-wrapper icon indicating copy to clipboard operation
poe-api-wrapper copied to clipboard

question about sent_message()

Open llllly26 opened this issue 1 year ago • 23 comments

Hi, i get the token through your step, and when i run the code, print(client.get_chat_history()) can return, but when i run the part about for chunk in client.send_message(bot, message):, there is nothing returned. then i debug the code, and i find that there is a problem about self.connect_ws() in api.py. in api.py-line223, self.ws_connected was false, so the program stucks in an infinite loop. But the other one that use my token can correctly run the code, i don't know what is wrong of me.

llllly26 avatar Sep 12 '23 04:09 llllly26

I will update the api soon

snowby666 avatar Sep 13 '23 17:09 snowby666

Can you check if this error still occur with the new version?

snowby666 avatar Sep 14 '23 14:09 snowby666

Can you check if this error still occur with the new version? Hi, i still can not run sucessfully. This time, i even can not run the code print(client.get_chat_history()). But I can run in the old version. The new error is in api.py, line 256, in connect_ws that: image so, i can't verify the send_message() either.
This time i also can not successfully connect.What's wrong? Thank you!

llllly26 avatar Sep 15 '23 04:09 llllly26

Can you check if you re using vpn or proxy while running this code? And It would be better if you can specify your OS and python version.

snowby666 avatar Sep 15 '23 05:09 snowby666

I think there might be a problem with your SSL/TLS setup. If possible can you fork this repo, adjust this line and test on your local machine: line 169 :

self.channel_url = f'wss://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

to this one:

self.channel_url = f'ws://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

snowby666 avatar Sep 15 '23 10:09 snowby666

Can you check if you re using vpn or proxy while running this code? And It would be better if you can specify your OS and python version.

my OS is win10,and my python version is 3.10.12

llllly26 avatar Sep 15 '23 11:09 llllly26

I think there might be a problem with your SSL/TLS setup. If possible can you fork this repo, adjust this line and test on your local machine: line 169 :

self.channel_url = f'wss://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

to this one:

self.channel_url = f'ws://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

the question is still remaining.

llllly26 avatar Sep 15 '23 11:09 llllly26

I think there might be a problem with your SSL/TLS setup. If possible can you fork this repo, adjust this line and test on your local machine: line 169 :

self.channel_url = f'wss://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

to this one:

self.channel_url = f'ws://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

if the problem is from the port? in my win10, http(s) port is: 4780; socks port is 4781. whether your code use port anywhere? image

llllly26 avatar Sep 15 '23 12:09 llllly26

can you check this for me? https://poe.com/api/settings

snowby666 avatar Sep 16 '23 06:09 snowby666

https://poe.com/api/settings

{"tchannelData":{"minSeq":"8130883414","channel":"poe-chan60-8888-mkhevzuqednzwejckppj","channelHash":"15169644638001127031","boxName":"chan60-8888","baseHost":"poe.com","targetUrl":"","enableWebsocket":true}}

llllly26 avatar Sep 16 '23 11:09 llllly26

I think there might be a problem with your SSL/TLS setup. If possible can you fork this repo, adjust this line and test on your local machine: line 169 :

self.channel_url = f'wss://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

to this one:

self.channel_url = f'ws://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

if the problem is from the port? in my win10, http(s) port is: 4780; socks port is 4781. whether your code use port anywhere? image

No, the lib doesn't use port. How about setting up a virtual environment to test it first. This time try using requests or httpx lib then send a request to a url to check if it works

snowby666 avatar Sep 16 '23 16:09 snowby666

I think there might be a problem with your SSL/TLS setup. If possible can you fork this repo, adjust this line and test on your local machine: line 169 :

self.channel_url = f'wss://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

to this one:

self.channel_url = f'ws://{self.ws_domain}.tch.{self.tchannel_data["baseHost"]}/up/{self.tchannel_data["boxName"]}/updates?min_seq={self.tchannel_data["minSeq"]}&channel={self.tchannel_data["channel"]}&hash={self.tchannel_data["channelHash"]}'

if the problem is from the port? in my win10, http(s) port is: 4780; socks port is 4781. whether your code use port anywhere? image

No, the lib doesn't use port. How about setting up a virtual environment to test it first. This time try using requests or httpx lib then send a request to a url to check if it works

hi, how to test it?

llllly26 avatar Sep 17 '23 01:09 llllly26

First create a venv in your folder:

python -m venv .venv
.venv\Scripts\activate.bat      

Then create a test.py

import requests
import httpx

url = 'http://example.com'

try:
    response = requests.get(url)
    if response.status_code == 200:
        print("Connection successful. Ping to example.com using requests was sent.")
    else:
        print("Connection failed. Unable to ping example.com using requests.")
except requests.exceptions.RequestException as e:
    print("Connection failed. Exception:", e)
    
    
try:
    with httpx.Client() as client:
        response = client.get(url)
        if response.status_code == 200:
            print("Connection successful. Ping to example.com using httpx was sent.")
        else:
            print("Connection failed. Unable to ping example.com using httpx.")
except httpx.RequestError as e:
    print("Connection failed. Exception:", e)

Run test.py

python test.py

snowby666 avatar Sep 17 '23 02:09 snowby666

First create a venv in your folder:

python -m venv .venv
.venv\Scripts\activate.bat      

Then create a test.py

import requests
import httpx

url = 'http://example.com'

try:
    response = requests.get(url)
    if response.status_code == 200:
        print("Connection successful. Ping to example.com using requests was sent.")
    else:
        print("Connection failed. Unable to ping example.com using requests.")
except requests.exceptions.RequestException as e:
    print("Connection failed. Exception:", e)
    
    
try:
    with httpx.Client() as client:
        response = client.get(url)
        if response.status_code == 200:
            print("Connection successful. Ping to example.com using httpx was sent.")
        else:
            print("Connection failed. Unable to ping example.com using httpx.")
except httpx.RequestError as e:
    print("Connection failed. Exception:", e)

Run test.py

python test.py

hi, it can work. image

llllly26 avatar Sep 17 '23 06:09 llllly26

Alright it seems like the issues didnt come from the httpx lib, how about the websocket-client lib then. Can you do 1 more test for me (in venv as well)

import websocket

def on_open(ws):
    print("WebSocket connection established")
    ws.send("Hello, server!")

def on_message(ws, message):
    print("Received message from server:", message)

def on_close(ws, close_status_code, close_msg):
    print("Websocket connection closed with status code:", close_status_code, "and message:", close_msg)

def on_error(ws, error):
    print("WebSocket error:", error)

url = "wss://javascript.info/article/websocket/demo/hello"

ws = websocket.WebSocketApp(url,
                            on_open=on_open,
                            on_message=on_message,
                            on_close=on_close,
                            on_error=on_error)
ws.run_forever()

snowby666 avatar Sep 17 '23 07:09 snowby666

import websocket

def on_open(ws):
    print("WebSocket connection established")
    ws.send("Hello, server!")

def on_message(ws, message):
    print("Received message from server:", message)

def on_close(ws, close_status_code, close_msg):
    print("Websocket connection closed with status code:", close_status_code, "and message:", close_msg)

def on_error(ws, error):
    print("WebSocket error:", error)

url = "wss://javascript.info/article/websocket/demo/hello"

ws = websocket.WebSocketApp(url,
                            on_open=on_open,
                            on_message=on_message,
                            on_close=on_close,
                            on_error=on_error)
ws.run_forever()

that's ok. image

llllly26 avatar Sep 17 '23 07:09 llllly26

can you try this again in your venv?

for chunk in client.send_message(bot, message):,
     print(chunk['response'], end='', flush=True)

snowby666 avatar Sep 17 '23 08:09 snowby666

for chunk in client.send_message(bot, message):,
     print(chunk['response'], end='', flush=True)

I'm sorry, that it still has the same problems. image

code is:

client = PoeApi(token)
print(client.get_chat_history())

bot = "chinchilla"
message = "What is reverse engineering?"
#
output = ""
for chunk in client.send_message(bot, message):
    output += chunk["response"]
print(output)

llllly26 avatar Sep 17 '23 11:09 llllly26

Can you check your quora token if its valid? You must also login poe.com with the same account on quora

snowby666 avatar Sep 17 '23 11:09 snowby666

Can you check your quora token if its valid? You must also login poe.com with the same account on quora

yes, my token that can run successully because i give it to the other one, and he can run successful, but i can't. --

llllly26 avatar Sep 17 '23 12:09 llllly26

import websocket

def on_open(ws):
    print("WebSocket connection established")
    ws.send("Hello, server!")

def on_message(ws, message):
    print("Received message from server:", message)

def on_close(ws, close_status_code, close_msg):
    print("Websocket connection closed with status code:", close_status_code, "and message:", close_msg)

def on_error(ws, error):
    print("WebSocket error:", error)

url = "wss://javascript.info/article/websocket/demo/hello"

ws = websocket.WebSocketApp(url,
                            on_open=on_open,
                            on_message=on_message,
                            on_close=on_close,
                            on_error=on_error)
ws.run_forever()

that's ok. image

How long did it take you to connect to the ws with this code? Maybe the timeout in the api is too short.

snowby666 avatar Sep 18 '23 12:09 snowby666

import websocket

def on_open(ws):
    print("WebSocket connection established")
    ws.send("Hello, server!")

def on_message(ws, message):
    print("Received message from server:", message)

def on_close(ws, close_status_code, close_msg):
    print("Websocket connection closed with status code:", close_status_code, "and message:", close_msg)

def on_error(ws, error):
    print("WebSocket error:", error)

url = "wss://javascript.info/article/websocket/demo/hello"

ws = websocket.WebSocketApp(url,
                            on_open=on_open,
                            on_message=on_message,
                            on_close=on_close,
                            on_error=on_error)
ws.run_forever()

that's ok. image

How long did it take you to connect to the ws with this code? Maybe the timeout in the api is too short.

about 5s.

llllly26 avatar Sep 18 '23 14:09 llllly26

what is the specifical proxy? how to use the proxy? when i use poe, i need the vpn, so whether i need the proxy version? how to use it?

llllly26 avatar Sep 23 '23 15:09 llllly26

This is be fixed in v.1.5.4

snowby666 avatar Jun 21 '24 07:06 snowby666