Skip to content
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

pytg: INFO CLI did not responde #128

Open
ezhevpelikan opened this issue Dec 15, 2017 · 1 comment
Open

pytg: INFO CLI did not responde #128

ezhevpelikan opened this issue Dec 15, 2017 · 1 comment

Comments

@ezhevpelikan
Copy link

The problem

Hi all!
Log output:
ConnectionResetError: [Errno 104] Connection reset by peer
2017-12-15 10:10:06,661 pytg: INFO CLI did not responde.

Actual behaviour

Tell us what happens instead.

Your environment

ubuntu:16.04

Component Version
python 3.5.2
pytg   0.4.10  
OS     `Linux d3360e5bd9d9 4.4.0-98-generic #121-Ubuntu SMP Tue Oct 10 14:24:03 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Steps to reproduce

Detailed steps to reproduce the issue.

# coding=utf-8

import time
import os

from pytg import Telegram
from pytg.utils import coroutine

import requests
from pytg import exceptions
from datetime import datetime
import logging
from socket import error as SocketError
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(name)s: %(levelname)s %(message)s')

def post_to_db(post):
    # do something

def main():
    home_dir = os.environ.get("TELEGRAM_HOME")
    port = os.environ.get("TELEGRAM_PORT")

    tg = Telegram(
        telegram="/tg-cli/telegram-cli",
        port = int(port),
        pubkey_file="/tg-cli/tg-server.pub",
        home_directory=home_dir)
    receiver = tg.receiver
    sender = tg.sender

    try:
        receiver.start()
    except Exception as e:
        logging.info("cannot start receiver for receive new messages: {error}".format(str(e)))
        receiver.stop()
        quit()

    try:
        receiver.message(message_func(sender))
    except SocketError as e:
        logging.info("cannot receive new messages: {error}".format(str(e)))
        receiver.stop()
        sender.safe_quit()
    except Exception as e:
        logging.info("cannot receive new messages: {error}".format(str(e)))
        receiver.stop()
        sender.safe_quit()

    receiver.stop()
    sender.safe_quit()

@coroutine
def message_func(sender):
    try:
        while True:
            msg = (yield)
            try:
                sender.status_online()
                msg = dict(msg)
                # print (msg)
                if msg.get("event") != "message":
                    continue
                if msg.get("text") is None:
                    continue
                elif "from" in msg:
                    post_to_db(post)
                elif "to" in msg:
                    post_to_db(post)
                elif "sender" in msg:
                    post_to_db(post)
                else:
                    quit()
            except exceptions.NoResponse:
                quit()
    except KeyboardInterrupt:
        quit()
    except Exception as e:
        print (e)
        logging.info("could not receive new messages: {error}".format(str(e)))
        quit()
    except GeneratorExit:
        # pass
        quit()
    else:
        # pass
        quit()

if __name__ == '__main__':
    main()

@luckydonald
Copy link
Owner

luckydonald commented Feb 1, 2018

Heya, could you set the logging level to logging.DEBUG instead of logging.INFO, to give more information?

Also, using logging.exception("whatever") instead of print(e) will print you the stacktrace of an Exception, giving me a bit more to work with.

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