Yowsup: sample application error

Created on 7 Jun 2019  路  12Comments  路  Source: tgalal/yowsup

I'm triying to do a sample application using the same code as https://github.com/tgalal/yowsup/wiki/Sample-Application

but I have an error when I use python run.py

Traceback (most recent call last):  
  File "run.py", line 1, in <module>
    from yowsup.layers.interface                           import YowInterfaceLayer, ProtocolEntityCallback
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/layers/interface/__init__.py", line 1, in <module>
    from .interface import YowInterfaceLayer, ProtocolEntityCallback
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/layers/interface/interface.py", line 5, in <module>
    from yowsup.layers.protocol_media.mediauploader import MediaUploader
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/layers/protocol_media/mediauploader.py", line 1, in <module>
    from yowsup.common.http.warequest import WARequest
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/common/http/__init__.py", line 2, in <module>
    from .warequest import WARequest
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/common/http/warequest.py", line 2, in <module>
    from yowsup.env import YowsupEnv
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/env/__init__.py", line 1, in <module>
    from .env import YowsupEnv
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/env/env.py", line 17, in <module>
    class YowsupEnv(with_metaclass(YowsupEnvType, object)):
  File "/usr/lib/python2.7/abc.py", line 87, in __new__
    cls = super(ABCMeta, mcls).__new__(mcls, name, bases, namespace)
TypeError: Error when calling the metaclass bases
    metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

Versions
__Python:__ 2.7.13
__yowsup-cli:__ v3.2.0
using:
yowsup v3.2.3
python-axolotl v0.2.2
dissononce v0.34.3
cryptography v2.7
protobuf v3.8.0
consonance v0.1.3-1

To Reproduce
python run.py with sample application saw here https://github.com/tgalal/yowsup/wiki/Sample-Application

All 12 comments

"For a fully working example checkout /yowsup/demos/echoclient"

There is no run.py because it runs from yowsup-cli but you can use this code:

from yowsup.stacks import  YowStackBuilder
from layer import EchoLayer
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
from yowsup.env import YowsupEnv


stackBuilder = YowStackBuilder()

stack = stackBuilder\
    .pushDefaultLayers()\
    .push(EchoLayer)\
    .build()

stack.setProfile("your_profile")
YowsupEnv.setEnv("android")
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
stack.loop()

Hi @NelsonGaldeman thanks for your answer :)

Now I'm using the next files in folder yowsup/demos/echoclient:

__layer.py__

from yowsup.layers.interface                           import YowInterfaceLayer, ProtocolEntityCallback

class EchoLayer(YowInterfaceLayer):

    @ProtocolEntityCallback("message")
    def onMessage(self, messageProtocolEntity):

        if messageProtocolEntity.getType() == 'text':
            self.onTextMessage(messageProtocolEntity)
        elif messageProtocolEntity.getType() == 'media':
            self.onMediaMessage(messageProtocolEntity)

        self.toLower(messageProtocolEntity.forward(messageProtocolEntity.getFrom()))
        self.toLower(messageProtocolEntity.ack())
        self.toLower(messageProtocolEntity.ack(True))


    @ProtocolEntityCallback("receipt")
    def onReceipt(self, entity):
        self.toLower(entity.ack())

    def onTextMessage(self,messageProtocolEntity):
        # just print info
        print("Echoing %s to %s" % (messageProtocolEntity.getBody(), messageProtocolEntity.getFrom(False)))

    def onMediaMessage(self, messageProtocolEntity):
        # just print info
        if messageProtocolEntity.media_type == "image":
            print("Echoing image %s to %s" % (messageProtocolEntity.url, messageProtocolEntity.getFrom(False)))

        elif messageProtocolEntity.media_type == "location":
            print("Echoing location (%s, %s) to %s" % (messageProtocolEntity.getLatitude(), messageProtocolEntity.getLongitude(), messageProtocolEntity.getFrom(False)))

        elif messageProtocolEntity.media_type == "contact":
            print("Echoing contact (%s, %s) to %s" % (messageProtocolEntity.getName(), messageProtocolEntity.getCardData(), messageProtocolEntity.getFrom(False)))

__stack.py__

from yowsup.stacks import  YowStackBuilder
from .layer import EchoLayer
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer


class YowsupEchoStack(object):
    def __init__(self, profile):
        stackBuilder = YowStackBuilder()

        self._stack = stackBuilder\
            .pushDefaultLayers()\
            .push(EchoLayer)\
            .build()

        self._stack.setProfile(profile)

    def set_prop(self, key, val):
        self._stack.setProp(key, val)

    def start(self):
        self._stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
        self._stack.loop()

__run.py__

from yowsup.stacks import  YowStackBuilder
from layer import EchoLayer
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
from yowsup.env import YowsupEnv


stackBuilder = YowStackBuilder()

stack = stackBuilder\
    .pushDefaultLayers()\
    .push(EchoLayer)\
    .build()

stack.setProfile("your_profile")
YowsupEnv.setEnv("android")
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
stack.loop()

In stack.setProfile("your_profile") instead use "your_profile" I use my phone number with cc, It麓s correct?

Now, when I use python run.pi I get the next error:

Traceback (most recent call last):
  File "run.py", line 1, in <module>
    from yowsup.stacks import  YowStackBuilder
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/stacks/__init__.py", line 1, in <module>
    from .yowstack import YowStack, YowStackBuilder
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/stacks/yowstack.py", line 4, in <module>
    from yowsup.layers.auth                        import YowCryptLayer, YowAuthenticationProtocolLayer
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/layers/auth/__init__.py", line 1, in <module>
    from .layer_crypt import YowCryptLayer
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/layers/auth/layer_crypt.py", line 2, in <module>
    from yowsup.layers.network import YowNetworkLayer
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/layers/network/__init__.py", line 1, in <module>
    from .layer import YowNetworkLayer
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/layers/network/layer.py", line 2, in <module>
    from yowsup.common.http.httpproxy import HttpProxy
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/common/http/__init__.py", line 2, in <module>
    from .warequest import WARequest
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/common/http/warequest.py", line 4, in <module>
    from yowsup.env import YowsupEnv
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/env/__init__.py", line 1, in <module>
    from .env import YowsupEnv
  File "/home/pi/.local/lib/python2.7/site-packages/yowsup/env/env.py", line 13, in <module>
    class YowsupEnv(with_metaclass(YowsupEnvType, object)):
  File "/usr/lib/python2.7/abc.py", line 87, in __new__
    cls = super(ABCMeta, mcls).__new__(mcls, name, bases, namespace)
TypeError: Error when calling the metaclass bases
    metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases

It seems that I always have errors with import. It麓s possible that I need to install something else?

Echo demo works fine in yowsup-cli.

Thank you for your help.

Greetings

You don't need stack.py.
Yes, you must replace "your_profile" with your previously registered phone number. Please check your profile config.json file is in place. You must match the profile number format with the one in the code.

Are you using the last release version or the code in the master branch? If last, please post the last commit hash you got.

Hi @NelsonGaldeman ..
When trying your last suggestion I got this error:

File "run.py", line 15, in <module> stack.setProfile("5nnnnnnnnn") AttributeError: 'YowStack' object has no attribute 'setProfile'

You don't need stack.py.
Yes, you must replace "your_profile" with your previously registered phone number. Please check your profile config.json file is in place. You must match the profile number format with the one in the code.

Are you using the last release version or the code in the master branch? If last, please post the last commit hash you got.

I'm pulling from master branch updated with the last changes:

commit 7f336c7c300ffe00e04be339f029ff23679fa1c1
Author: Mike Salmon <[email protected]>
Date:   Mon Jun 10 10:55:52 2019 +0100

    Removed duplicate function

    Removed duplicate `def __str__` function in `demos/cli/layer.py` file

Where is the config.json file? I can麓t find it. I have a profile folder with a profile.py file but I haven't got any file called config.json.

Under Windows should be in %USERPROFILE%/AppData/Local/yowsup/yowsup/PHONE_NUMBER/config.json

You are using Linux so I assume there is a folder called yowsup or .yowsup in your home dir.

Here is mine
imagen

@bottasergio please open a new issue with all the needed information.

@adominguez

I have the same problem as you

run.py

from yowsup.stacks import  YowStackBuilder
from layer import EchoLayer
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
from yowsup.env import YowsupEnv


stackBuilder = YowStackBuilder()

stack = stackBuilder\
    .pushDefaultLayers()\
    .push(EchoLayer)\
    .build()

stack.setProfile("xxxxxxxxxxxxxxx")
YowsupEnv.setEnv("android")
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
stack.loop()
  File "/root/.yowsup/run.py", line 15, in <module>
    stack.setProfile("xxxxxxxxxxxxxxx")
AttributeError: 'YowStack' object has no attribute 'setProfile'

@NelsonGaldeman

could you please post your complete run.py?

Very thanks

Hi @NelsonGaldeman and @langioletto.

In my case, I'm using raspbian, I have in .yowsup a folder with name my cc and phone number ok.

yowsup-phone

Inside folder, I have 2 files: axolot.db and id, I haven't got any file config.json. it麓s a possible error?

yowsup-phone-2

Thank you for your help!

@adominguez did you registered your WhatsApp number with yousup-cli?
Or is there any possibility that you have your whatsapp number activated on another device?

@langioletto you should create a new issue providing all the needed information to help you. Btw, I've already posted my run.py here, you only need to change the profile.

@adominguez did you registered your WhatsApp number with yousup-cli?
Or is there any possibility that you have your whatsapp number activated on another device?

@langioletto you should create a new issue providing all the needed information to help you. Btw, I've already posted my run.py here, you only need to change the profile.

Yes, I have registered my phone number in yowsup-cli, for example, the echoclient, mediasink and sendclient demos are working using yowsup-cli, but I can't use it with python run.py command. :(

yowsup-phone-3
This is an echoclient demo example working with yowsup-cli

I think that I don`t have whatsapp number activated on another device. It麓s possible to check this by one way?

@adominguez you are showing a directory from an old yowsup version, delete this folder as it's not used. Storage is now at ~/.config/yowsup/.

Locking the issue as it went beyond the original topic, sample application error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EliasinnKamachoo picture EliasinnKamachoo  路  3Comments

mathslimin picture mathslimin  路  4Comments

bahtiarp picture bahtiarp  路  4Comments

Realitaetsverlust picture Realitaetsverlust  路  4Comments

thatskriptkid picture thatskriptkid  路  3Comments