jlguardi / yowsup

The python WhatsApp library
http://www.openwhatsapp.org
GNU General Public License v3.0
42 stars 23 forks source link

[TODO] Fix error sending location #14

Closed cfenollosa closed 8 years ago

cfenollosa commented 8 years ago

Hi @jlguardi,

I updated the code to the latest master (plus axolotl dev) and now location messages drop an error when sending:

Unhandled exception in thread started by <bound method Layer.send_reply_delayed of <layer_whatsapp.layer.Layer object at 0x7f283f933c10>>
Traceback (most recent call last):
  File "/home/astx/whatsbot/whatsapp-bot/layer_whatsapp/layer.py", line 170, in send_reply_delayed
    self.toLower(entity)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 79, in toLower
    self.__lower.send(data)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 192, in send
    s.send(data)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 130, in send
    send(entity)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/protocol_media/layer.py", line 35, in sendMessageEntity
    self.entityToLower(entity)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 134, in entityToLower
    self.toLower(entity.toProtocolTreeNode())
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 79, in toLower
    self.__lower.send(data)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 120, in send
    self.handlePlaintextNode(node)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 188, in handlePlaintextNode
    messageData = self.serializeToProtobuf(node) if v2 else node.getChild("body").getData()
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 423, in serializeToProtobuf
    return self.serializeMediaToProtobuf(node.getChild("media"))
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 437, in serializeMediaToProtobuf
    return self.serializeLocationToProtobuf(mediaNode)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 446, in serializeLocationToProtobuf
    location_message.degress_latitude = float(mediaNode["latitude"])
AttributeError: 'LocationMessage' object has no attribute 'degress_latitude'
yniv commented 8 years ago

I'm having this problem too. thnks.

jlguardi commented 8 years ago

I've never tried ;) I'll fix today.

cfenollosa commented 8 years ago

Thanks!

Here's sample code so that you don't need to search for it:

entity = LocationMediaMessageProtocolEntity('41.3780485', '2.1249203', 'Example location', 'http://example.com', to='34666123456@s.whatsapp.net')
self.toLower(entity)
cfenollosa commented 8 years ago

Hi, it's still not working, you need to change lines 525 and 526 in axolotl/layer.py, "degress" to "degrees" too, and then it drops more errors:

Unhandled exception in thread started by <bound method LayerRacc.send_reply_delayed of <layer_whatsapp.layer_racc.LayerRacc object at 0x7f692b75a710>>
Traceback (most recent call last):
  File "/home/astx/whatsbot/whatsapp-bot/layer_whatsapp/layer_racc.py", line 170, in send_reply_delayed
    self.toLower(entity)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 79, in toLower
    self.__lower.send(data)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 192, in send
    s.send(data)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 130, in send
    send(entity)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/protocol_media/layer.py", line 37, in sendMessageEntity
    self.entityToLower(entity)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 134, in entityToLower
    self.toLower(entity.toProtocolTreeNode())
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/__init__.py", line 79, in toLower
    self.__lower.send(data)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 122, in send
    self.handlePlaintextNode(node)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 190, in handlePlaintextNode
    messageData = self.serializeToProtobuf(node) if v2 else node.getChild("body").getData()
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 502, in serializeToProtobuf
    return self.serializeMediaToProtobuf(node.getChild("media"))
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 516, in serializeMediaToProtobuf
    return self.serializeLocationToProtobuf(mediaNode)
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/yowsup2-2.4.48-py2.7.egg/yowsup/layers/axolotl/layer.py", line 532, in serializeLocationToProtobuf
    return m.SerializeToString()
  File "/home/astx/whatsbot/env/local/lib/python2.7/site-packages/google/protobuf/internal/python_message.py", line 831, in SerializeToString
    self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
google.protobuf.message.EncodeError: Message com.whatsapp.proto.Message is missing required fields: location_message.jpeg_thumbnail
jlguardi commented 8 years ago

I've never tested ;) I'll fix!

cfenollosa commented 8 years ago

Thanks! By the way, I'm using protobuf==3.0.0-alpha-1

jlguardi commented 8 years ago

I've fixed typos in media while sending encrypted but they aren't still received (I get ack and receipt but not seen). I'll continue but this issue is fixed.