Skip to content

Recieve messages failed: {'information': '', 'exception': ReadError('')} #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MtkN1 opened this issue Mar 25, 2025 · 4 comments
Open

Comments

@MtkN1
Copy link

MtkN1 commented Mar 25, 2025

I added pubnub.publish to the main function in examples/pubnub_asyncio_simple/main.py. After that, pressing Ctrl+C results in the following error output (ReadError). What could be the issue?

Python 3.13

import asyncio
import os

from pubnub.enums import PNStatusCategory
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub_asyncio import PubNubAsyncio, SubscribeCallback


class MySubscribeCallback(SubscribeCallback):
    def status(self, pubnub, status):
        if status.category == PNStatusCategory.PNUnexpectedDisconnectCategory:
            print("Disconnected")
        elif status.category == PNStatusCategory.PNConnectedCategory:
            print("Connected")
        elif status.category == PNStatusCategory.PNReconnectedCategory:
            print("Reconnected")
        elif status.category == PNStatusCategory.PNDecryptionErrorCategory:
            print("Decryption error")

    def message(self, pubnub, message):
        print(f"Received message: {message.message} on channel: {message.channel}")

    def presence(self, pubnub, presence):
        print(f"Presence event: {presence.event}")


async def main(pubnub):
    pubnub.subscribe().channels("my_channel").execute()

    # Added
    await asyncio.sleep(1)
    await pubnub.publish(
        channel="my_channel", message="Hello from PubNub Python SDK"
    ).future()

    print("Listening for messages...")
    while True:
        await asyncio.sleep(1)


if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    pnconfig = PNConfiguration()
    pnconfig.subscribe_key = os.getenv("PUBNUB_SUBSCRIBE_KEY") or "demo"
    pnconfig.publish_key = os.getenv("PUBNUB_PUBLISH_KEY") or "demo"
    pnconfig.user_id = "my_unique_user_id"  # Set a unique user ID

    pubnub = PubNubAsyncio(pnconfig)
    callback = MySubscribeCallback()
    pubnub.add_listener(callback)

    try:
        loop.run_until_complete(main(pubnub))
    except KeyboardInterrupt:
        print("Interrupted by user. Exiting...")
    finally:
        loop.run_until_complete(pubnub.stop())  # Assuming 'pubnub' is in scope
        loop.close()
Connected
Listening for messages...
Received message: Hello from PubNub Python SDK on channel: my_channel
^CInterrupted by user. Exiting...
session.request exception: 
Recieve messages failed: {'information': '', 'exception': ReadError('')}
EventEngine is not enabled
@seba-aln
Copy link
Contributor

This is HTTPX's network read error caused by interrupting the request most probably.

@MtkN1
Copy link
Author

MtkN1 commented Mar 25, 2025

Is it possible to properly terminate the HTTPX network on the application side? I suspect that there might be an issue with the AsyncHttpxRequestHandler in the library or improper shutdown of the event loop.

@seba-aln
Copy link
Contributor

I will take a look into it soon.

@seba-aln
Copy link
Contributor

seba-aln commented Apr 8, 2025

I am in process of improving the error handlers so there should be some benefits soon. But from I already found the process seems to be cleaning up pretty decently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants