I am attempting to open a telnet socket using the example socket code from https://wiki.znc.in/Modpython - the socket creates and connects ok, but immediately disconnects and shuts down without ever triggering OnReadLine(). OnReadData triggers, despite EnableReadLine() having been used prior. If I put Write() statements immediately after Connect() the data is transmitted (and received) but the connection then closes. OnSockError() sees nothing (assuming this is exposed in modpython).
How do I get the socket to persist?
I am attempting to open a telnet socket using the example socket code from https://wiki.znc.in/Modpython - the socket creates and connects ok, but immediately disconnects and shuts down without ever triggering OnReadLine(). OnReadData triggers, despite EnableReadLine() having been used prior. If I put Write() statements immediately after Connect() the data is transmitted (and received) but the connection then closes. OnSockError() sees nothing (assuming this is exposed in modpython).
How do I get the socket to persist?
<!-- github-sync-id:954501290 -->
ÿû� looks concerning. Does the module stay loaded after the disconnect?
My suspicion is that it can't parse the line as UTF-8 (the default encoding), and reports the error via closing it.
OnReadData triggers, despite EnableReadLine() having been used prior
Correct. OnReadData triggers for all data. OnReadLine is triggered for lines only, after parsing them from raw bytes with the specified encoding.
Can you check `znc -D`?
`ÿû�` looks concerning. Does the module stay loaded after the disconnect?
My suspicion is that it can't parse the line as UTF-8 (the default encoding), and reports the error via closing it.
> OnReadData triggers, despite EnableReadLine() having been used prior
Correct. OnReadData triggers for all data. OnReadLine is triggered for lines only, after parsing them from raw bytes with the specified encoding.
<!-- github-comment-id:888178434 -->
[2021-07-28 22:06:31.886761] python socket failed in OnReadLine: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte\x0A
ÿû� looks concerning. Does the module stay loaded after the disconnect?
Yes, the module stays loaded.
Correct. OnReadData triggers for all data. OnReadLine is triggered for lines only, after parsing them from raw bytes with the specified encoding.
So possibly I'm never getting to that point as it's erroring and closing the socket when the decode fails.
> Can you check `znc -D`?
I think you're onto something - znc -D shows:
```
[2021-07-28 22:06:31.886761] python socket failed in OnReadLine: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte\x0A
```
> `ÿû�` looks concerning. Does the module stay loaded after the disconnect?
Yes, the module stays loaded.
> Correct. OnReadData triggers for all data. OnReadLine is triggered for lines only, after parsing them from raw bytes with the specified encoding.
So possibly I'm never getting to that point as it's erroring and closing the socket when the decode fails.
<!-- github-comment-id:888186305 -->
Either don't use EnableReadLine(), so that it doesn't try to decode the bytes at all, or specify the encoding via SetEncoding(), which supports some fallback options between UTF-8 and something else (which I should document somewhere...)
Either don't use `EnableReadLine()`, so that it doesn't try to decode the bytes at all, or specify the encoding via `SetEncoding()`, which supports some fallback options between UTF-8 and something else (which I should document somewhere...)
<!-- github-comment-id:888188576 -->
Either don't use EnableReadLine(), so that it doesn't try to decode the bytes at all, or specify the encoding via SetEncoding(), which supports some fallback options between UTF-8 and something else (which I should document somewhere...)
Awesome, thanks. Using SetEncoding('utf8') gets me past that point - will soldier on - thanks a lot!
> Either don't use `EnableReadLine()`, so that it doesn't try to decode the bytes at all, or specify the encoding via `SetEncoding()`, which supports some fallback options between UTF-8 and something else (which I should document somewhere...)
Awesome, thanks. Using `SetEncoding('utf8')` gets me past that point - will soldier on - thanks a lot!
<!-- github-comment-id:888204225 -->
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
I am attempting to open a telnet socket using the example socket code from https://wiki.znc.in/Modpython - the socket creates and connects ok, but immediately disconnects and shuts down without ever triggering OnReadLine(). OnReadData triggers, despite EnableReadLine() having been used prior. If I put Write() statements immediately after Connect() the data is transmitted (and received) but the connection then closes. OnSockError() sees nothing (assuming this is exposed in modpython).
How do I get the socket to persist?
Sorry, should have included the code. The host in question is an eggdrop bot, FYI.
Output to *status is:
Can you check
znc -D?ÿû�looks concerning. Does the module stay loaded after the disconnect?My suspicion is that it can't parse the line as UTF-8 (the default encoding), and reports the error via closing it.
Correct. OnReadData triggers for all data. OnReadLine is triggered for lines only, after parsing them from raw bytes with the specified encoding.
I think you're onto something - znc -D shows:
Yes, the module stays loaded.
So possibly I'm never getting to that point as it's erroring and closing the socket when the decode fails.
Either don't use
EnableReadLine(), so that it doesn't try to decode the bytes at all, or specify the encoding viaSetEncoding(), which supports some fallback options between UTF-8 and something else (which I should document somewhere...)Awesome, thanks. Using
SetEncoding('utf8')gets me past that point - will soldier on - thanks a lot!