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

Exception handler problem in sender #46

Closed
mariusl opened this issue Oct 15, 2015 · 14 comments
Closed

Exception handler problem in sender #46

mariusl opened this issue Oct 15, 2015 · 14 comments
Labels

Comments

@mariusl
Copy link

mariusl commented Oct 15, 2015

Hi
I found this error after I uploaded a photo with sender.send_photo.

[SUCCESS] dropbox account linked
[INFO] warming up...
[INFO] starting background model...
[UPLOAD] Thursday 15 October 2015 02:01:44PM
[IMAGE] .//b8d38bca-37e1-4e87-a332-58fbfc9a29f9.jpg //*** this is the filename of the image that I upload
No handlers could be found for logger "pytg.sender"
Traceback (most recent call last):
  File "sentry.py", line 159, in <module>
    sender.send_photo("Roaming_Camera", unicode(t.path))
  File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 548, in command_alias
  File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 259, in execute_function
pytg.exceptions.IllegalResponseException: Result parser does not allow exceptions.
@luckydonald
Copy link
Owner

This is #33 again. It just needs a dummy handler.

@mariusl
Copy link
Author

mariusl commented Oct 17, 2015

The problem for me is not so much the logging but the exception not handled. I actually get a problem with no_response from Telegram. The message goes through but there is an exception I can only assume is no_response. I commented all the "raise" statements out and made the timeout on the function 1 second. I get all my messages and photos through but the code is broken or missing a specific handler.

@mariusl
Copy link
Author

mariusl commented Oct 17, 2015

I put the logger stuff in and now have a lot more information reported. Maybe this will help. It does look like no_response from Telegram. I still have the "raise" commented out in the sender.

[SUCCESS] dropbox account linked
[INFO] warming up...
[INFO] starting background model...
[UPLOAD] Saturday 17 October 2015 09:14:50AM
[IMAGE]  .//5897f668-19bc-499f-b422-53e00b41c7fe.jpg
ERROR:pytg.sender:Result parser does not allow exceptions, but we got one: 
Traceback (most recent call last):
  File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 250, in execute_function
    result = self._do_command(command_name, new_args, answer_timeout=result_timeout, retry_connect=retry_connect, enable_preview=enable_preview, reply_id=reply_id)
  File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 360, in _do_command
    result = self._do_send(request, answer_timeout=answer_timeout, retry_connect=retry_connect)
  File "build/bdist.linux-armv7l/egg/pytg/sender.py", line 450, in _do_send
    raise NoResponse(command)
NoResponse:  [disable_preview] send_photo Roaming_Camera './/5897f668-19bc-499f-b422-53e00b41c7fe.jpg' 'Taken at - Saturday 17 October 2015 09:14:50AM'

ERROR:pytg.sender:Result parser did not allow exceptions.

(Security Feed:1905): GLib-GObject-WARNING **: Attempt to add property GtkSettings::gtk-label-select-on-focus after class was initialised
WARNING:pytg.sender:Terminating currently sending request.
WARNING:pytg.sender:Terminating currently sending request.
Exception in thread Receiver (pytg):
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "build/bdist.linux-armv7l/egg/pytg/receiver.py", line 128, in _receiver
    raise ConnectionError("Remote end closed.")
ConnectionError: Remote end closed.

@luckydonald
Copy link
Owner

I am not currently have a runnable telegram CLI configured, and didn't work on this for half an year. So I have no direct clue what's going on.

Can you please try what happens if you enter the sent command

 [disable_preview] send_photo Roaming_Camera './/5897f668-19bc-499f-b422-53e00b41c7fe.jpg' 'Taken at - Saturday 17 October 2015 09:14:50AM'

manually in the cli (with json enabled)?

@luckydonald
Copy link
Owner

Next step we could test:
What happens if you run that code via the socket?
Use some tool like netcat with the specified port (e.g. 4458) .

$ nc localhost 4458

Then see if that command works, and if you get a response.
Also, how long does it takes?

@mariusl
Copy link
Author

mariusl commented Oct 18, 2015

I did tyhe test from within cli and it was immediate. The response is included in the code below. I tried the netcat test but cannot get it to work. Also see below. I dont know netcall at all so I can't say that I did it right.

pi@rpi2b /usr/local/src/tg $ bin/telegram-cli -k tg-server.pub -W
Telegram-cli version 1.3.3, Copyright (C) 2013-2015 Vitaly Valtman
Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show_license' for details.
Telegram-cli uses libtgl version 2.0.3
Telegram-cli includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit. (http://www.openssl.org/)
Telegram-cli uses libpython version 2.7.3
I: config dir=[/home/pi/.config/telegram-cli]

> send_photo Roaming_Camera /home/pi/development/pi-home-surveillance/dec6dd43-b707-48fb-94f3-585b60a7ca43.jpg 
[10:53]  Roaming Camera Sentry Camera >>> [photo] 

Netcat result

pi@rpi2b /usr/local/src/tg $ nc localhost 4458 send_photo Roamin_Camera /home/pi/development/pi-home-surveillance/dec6dd43-b707-48fb-94f3-585b60a7ca43.jpg 
nc: getaddrinfo: Servname not supported for ai_socktype

@luckydonald
Copy link
Owner

sorry, I forgot to mention to start the additonal cli parameters listening to the port, and netcat was unclear.

 bin/telegram-cli -k tg-server.pub -W --json -P 4458

Please retry both.
Netcat works by first connecting to it

$ nc localhost 4458 [enter]

and then typing your commands as you would in the CLI

@mariusl
Copy link
Author

mariusl commented Oct 19, 2015

Ok I got netcat going. I opened telegram as you asked with no problem and I sent messages as below. All with no problem and no delay.

This what I done:-
pi@rpi2b /usr/local/src/tg $ nc localhost 4485
send_photo Roaming_Camera /home/pi/development/pi-home-surveillance/dec6dd43-b707-48fb-94f3-585b60a7ca43.jpg
ANSWER 0

msg Roaming_Camera Test Message
ANSWER 0

Don't see anything strange unless you did not exdpect a 0 in the answer

@luckydonald
Copy link
Owner

ANSWER 0 means empty answer. It should return something like {"status": "success"} instead...
You are sure --json is enabled?

@mariusl
Copy link
Author

mariusl commented Oct 19, 2015

This is how I called telegram and the output from that.

pi@rpi2b /usr/local/src/tg $ bin/telegram-cli -k tg-server.pub -W --json -P 4485
Telegram-cli version 1.3.3, Copyright (C) 2013-2015 Vitaly Valtman
Telegram-cli comes with ABSOLUTELY NO WARRANTY; for details type `show_license'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show_license' for details.
Telegram-cli uses libtgl version 2.0.3
Telegram-cli includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit. (http://www.openssl.org/)
Telegram-cli uses libpython version 2.7.3
I: config dir=[/home/pi/.config/telegram-cli]

@luckydonald
Copy link
Owner

If you get a message or some other event, is that json format?

@mariusl
Copy link
Author

mariusl commented Oct 19, 2015

My application only makes use of sender. I dont read anything back at this time so I cant answer. I can try something if you want to make a suggestion on how to do that.

@luckydonald
Copy link
Owner

When your CLI recieves a message, can you post that output?

(sorry for the delay)

@luckydonald
Copy link
Owner

This should be the same as #50 and should be resolved by commit f745d92

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

No branches or pull requests

2 participants