danielcardeenas / whatsapp-framework

⚗️Whatsapp python api
1.16k stars 362 forks source link

error when receiving non-text messages #77

Open jhonarodriguez opened 6 years ago

jhonarodriguez commented 6 years ago

I'm implementing the whatsapp bot on mac IOS and every time I send an audio, image or location, there are a lot of errors and at the end it says "Whatsapp bot crashed with code 1. Respawning .." and the console is reset and I ask for a password again start the bot, Two questions:

  1. you can fix the error when they send any file, I'm only interested in the location of the user, no images or audio.

  2. If this is not possible, I can avoid errors and only take the text, sending it either empty or 0

I really appreciate it very much.

PD: Excellent repository, this is very useful, continue with your project, you will help us many ...

jhonarodriguez commented 6 years ago

What happens most of all, is when an image is sent, I should say something like an error message not valid or something like that, with any type of message that is not text, I do not know where to do it, I've searched everywhere and I can not find any solution ... I show the error that comes out when receiving an image:

Traceback (most recent call last): File "run.py", line 57, in c.start() File "run.py", line 38, in start self.stack.loop(timeout=0.5, discrete=0.5) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/stacks/yowstack.py", line 188, in loop asyncore.loop(*args, **kwargs) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 203, in loop poll_fun(timeout, map) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 150, in poll read(obj) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 87, in read obj.handle_error() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 83, in read obj.handle_read_event() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncore.py", line 423, in handle_read_event self.handle_read() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/network/layer.py", line 102, in handle_read self.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/network/layer.py", line 110, in receive self.toUpper(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 79, in toUpper self.upper.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/stanzaregulator/layer.py", line 29, in receive self.processReceived() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/stanzaregulator/layer.py", line 49, in processReceived self.toUpper(oneMessageData) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 79, in toUpper self.upper.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/auth/layer_crypt.py", line 65, in receive self.toUpper(payload) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 79, in toUpper self.upper.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/coder/layer.py", line 35, in receive self.toUpper(node) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 79, in toUpper self.upper.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/logger/layer.py", line 14, in receive self.toUpper(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 79, in toUpper self.upper.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/axolotl/layer_control.py", line 44, in receive self.toUpper(protocolTreeNode) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 79, in toUpper self.upper.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init__.py", line 194, in receive s.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/axolotl/layer_receive.py", line 46, in receive self.onMessage(protocolTreeNode) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/axolotl/layer_receive.py", line 80, in onMessage self.handleEncMessage(protocolTreeNode) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/axolotl/layer_receive.py", line 95, in handleEncMessage self.handleWhisperMessage(node) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/axolotl/layer_receive.py", line 153, in handleWhisperMessage self.parseAndHandleMessageProto(encMessageProtocolEntity, plaintext[:-padding]) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/axolotl/layer_receive.py", line 221, in parseAndHandleMessageProto self.handleImageMessage(node, m.image_message) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/axolotl/layer_receive.py", line 282, in handleImageMessage self.toUpper(messageNode) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 79, in toUpper self.upper.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 194, in receive s.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 130, in receive recv(node) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/protocol_media/layer.py", line 44, in recvMessageStanza self.toUpper(entity) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/init.py", line 79, in toUpper self.upper.receive(data) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/interface/interface.py", line 80, in receive self.entity_callbacksentityType File "/Users/desarrollo3/Documents/WS/app/layer.py", line 70, in on_message print(message_entity) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/protocol_media/protocolentities/message_media_downloadable_image.py", line 40, in str out = super(ImageDownloadableMediaMessageProtocolEntity, self).str() File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yowsup2-2.5.2-py3.6.egg/yowsup/layers/protocol_media/protocolentities/message_media_downloadable.py", line 36, in str__ out += "File Hash: %s\n" % self.fileHash.encode('hex') AttributeError: 'bytes' object has no attribute 'encode' Whatsapp bot crashed with code 1. Respawning..

danielcardeenas commented 6 years ago

I'll check this

sealabr commented 6 years ago

try this..

https://github.com/tgalal/yowsup/pull/2253/commits/eeb995a770dc57420eb4469dfae3f5647e2f1cb1