Re: Response for PING in ircbot.

2021-02-09 Thread flaskee via Python-list


‐‐‐ Original Message ‐‐‐
On Saturday, January 30, 2021 11:50 AM, Bischoop wrote:

> Got problem with responding for Ping,
> tried so many ways to response
> and always end up with time out or other error.
> This time:
>


Is it possible to share your final Ping answer with the list?

I've had a long term Flask/Python issue where the site just dies.


(MY) External ping attempts still report the Flask site is functioning;
but accessing the pages returns 500 errors.

Apache is still running and other (non-Flask) sites
are still running on the Linux server.

I see no errors that might be causing this under /var/log/*,
or apache's error log;
or the site's access/error logs.

What I'd like to do is set up my own external monitor,
to at least known WHEN the site has died.

And I'm wondering if your PING might be better.

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Response for PING in ircbot.

2021-02-07 Thread flaskee via Python-list

‐‐‐ Original Message ‐‐‐
On Saturday, January 30, 2021 11:50 AM, Bischoop wrote:

> Got problem with responding for Ping, tried so many ways to response
> and always end up with time out or other error. This time:
>


Is it possible to share your final Ping answer?

I've had a long term Flask/Python issue where the site just dies.


(MY) External ping attempts still report the Flask site is functioning;
but accessing the pages returns 500 errors.

Apache is still running and other (non-Flask) sites are still running on the 
Linux server.

I see no errors that might be causing this under /var/log/*,
or apache's error log;
or the site's access/error logs.

What I'd like to do is set up my own external monitor,
to at least known WHEN the site has died.

And I'm wondering if your PING might be better.

Thanks!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Response for PING in ircbot.

2021-02-03 Thread dn via Python-list


On 04/02/2021 07.07, Dennis Lee Bieber wrote:
> On Tue, 02 Feb 2021 20:26:34 -0500, Random832 
> declaimed the following:
> 
> 
>> 1. It looks like you're forgetting to send \n\r
> 
>   Isn't the convention \r\n -- from the days of teletype, when the return
> took longer to complete than the line feed, so start return, have it finish
> while the line feed activates...

Yes, "CRLF" = Carriage Return (chr( 13 )) and Line-Feed (chr( 10 )).


>   The order didn't matter in the .strip() call as that strips any
> leading/trailing characters that match any of the provided set, it is not a
> "trim" of the exact sequence (hmm, looks like that would be require using
> string.removeprefix("\n\r").removesuffix("\n\r") if the expected sequence
> were such).

If every line ends with the same (odd) suffix, then why not slice the
string [ :-2 ]?

Alternately, consider str.translate() where both character codes are
removed, regardless of location.
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Response for PING in ircbot.

2021-02-02 Thread Random832
On Sat, Jan 30, 2021, at 11:50, Bischoop wrote:
> 
> Got problem with responding for Ping, tried so many ways to response
> and always end up with time out or other error. This time:

1. It looks like you're forgetting to send \n\r
2. i'm not sure if the server ping is guaranteed to have : character
3. if it does have : character you need to send everything after it even if it 
includes spaces
4. what happens if the data in recv includes more than one line of data, or 
partial line at the end? this isn't a proper way to handle irc protocol in 
general, let alone the ping command

> ERROR :(Ping timeout: 264 seconds)
> Traceback (most recent call last):
> s.send(bytes('PONG ' + data.split()[1], 'UTF-8'))
> BrokenPipeError: [Errno 32] Broken pipe
> 
> while True:
> time.sleep(2)
> data=s.recv(2040).decode('utf8')
> data = data.strip("\n\r")
> print(data)
> if data.find ("PING :"):
> s.send(bytes('PONG ' + data.split()[1], 'UTF-8'))
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Response for PING in ircbot.

2021-01-30 Thread Cameron Simpson
On 30Jan2021 16:50, Bischoop  wrote:
>Got problem with responding for Ping, tried so many ways to response
>and always end up with time out or other error. This time:
>
>ERROR :(Ping timeout: 264 seconds)
>Traceback (most recent call last):
>s.send(bytes('PONG ' + data.split()[1], 'UTF-8'))
>BrokenPipeError: [Errno 32] Broken pipe

This says you're getting EPIPE trying to send. What that means may 
depend on how your socket was set up, which you do not show. Is it a 
stream or a datagram, for example?

Let's look at the documentation for "send". No, not the docs.python.org 
documentation, but the underlying system call because the Python socket 
module is a very thin wrapper for the operating system socket 
operations.

I do not know your operating system, so I'm looking on a Linux system 
using the command "man 2 send" (which might be spelled "man -s 2 send" 
on some platforms):

Right off the bat it says:

The send() call may be used only when the  socket  is  in  a
connected state  (so  that the intended recipient is known).

The send() call may be used only when the  socket  is  in  a
onnected state  (so  that the intended recipient is known).
The only difference between send() and write(2) is the presence
of  flags.  With  a zero flags  argument, send() is equivalent
to write(2).  Also, the following call

   send(sockfd, buf, len, flags);

   is equivalent to

   sendto(sockfd, buf, len, flags, NULL, 0);

where the "NULL, 0" represents "no target address".

In Python you have a socket object "s" so that:

s.send(...

it equivalent to the C code:

send(s, ...

shown above.

So, to your error: you're getting EPIPE (that's the OS error behind 
BrokenPipeError), and looking in the manual page in the ERRORS section:

EPIPE  The  local  end  has  been  shut  down  on a connection
   oriented socket.  In this case, the process will also
   receive a  SIGPIPE unless MSG_NOSIGNAL is set.

and in BUGS:

Linux may return EPIPE instead of ENOTCONN.

so also looking for ENOTCONN:

If sendto() is used on a connection-mode (SOCK_STREAM,
SOCK_SEQPACKET) socket,  the arguments dest_addr and addrlen
are ignored (and the error EISCONN may be returned when they
are not NULL and 0),  and the  error ENOTCONN  is returned when
the socket was not actually connected.

and again in the ERRORS section:

ENOTCONN The socket is not connected, and no target has been given.

We're back to: what kind of socket it this?

A datagram socket (eg UDP) normally requires a target address, typically 
the address from which you received the first packet (the ping). A 
stream connection (eg TCP) needs to be connected.

If you're got a stream connection, getting a message implies that the 
connection has been established, and maybe the connection was closed 
before you sent your reply.

More detail needed, particularly: how is the socket set up, and what's 
doing the sending of the "ping"?

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Response for PING in ircbot.

2021-01-30 Thread Bischoop



Got problem with responding for Ping, tried so many ways to response
and always end up with time out or other error. This time:

ERROR :(Ping timeout: 264 seconds)
Traceback (most recent call last):
s.send(bytes('PONG ' + data.split()[1], 'UTF-8'))
BrokenPipeError: [Errno 32] Broken pipe

while True:
time.sleep(2)
data=s.recv(2040).decode('utf8')
data = data.strip("\n\r")
print(data)
if data.find ("PING :"):
s.send(bytes('PONG ' + data.split()[1], 'UTF-8'))

--
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list