yowsup icon indicating copy to clipboard operation
yowsup copied to clipboard

pass credentials from layer to stack

Open kwiiby opened this issue 11 years ago • 21 comments

Hi, I'm trying to set credentials by my layer (editing echoclient), but I can't..

Here is my code: self.YowInterfaceLayer.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, ("number", "password"))

Error: 'EchoLayer' object has no attribute 'YowInterfaceLayer'

I've tried to set credentials in layer, then in stack I access like this: EchoLayer.credentials but it says that EchoLayer has no attribute 'credentials'

kwiiby avatar Dec 13 '14 23:12 kwiiby

self.setProp instead of self.YowInterfaceLayer.setProp

tgalal avatar Dec 13 '14 23:12 tgalal

Ok, here is my code now: self.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, ("number", "password"))

Error: global name 'YowAuthenticationProtocolLayer' is not defined

Sorry if my questions are stupid, but I don't know so much about the architecture

kwiiby avatar Dec 13 '14 23:12 kwiiby

no you don't know much about python import YowAuthenticationProtocolLayer first

tgalal avatar Dec 13 '14 23:12 tgalal

yes, I really don't know much about python..

so, I tried to use: from yowsup.layers.auth import YowAuthenticationProtocolLayer not working.. I guess that a layer has nothing to do with a stack (hierarchically) So, I can't set a prop into the stack that is already instantiated and hierarchically won't have somehow link with the layer.. Am I right?

kwiiby avatar Dec 13 '14 23:12 kwiiby

props are set on stack level, when u do it from layer, it actually calls currentstack.setProp, and then u have access to it from all layers (which means it's possible on an instantiated layer/stack) But what exactly is not working? you might be setting YowAuthenticationProtocolLayer.PROP_CREDENTIALS after trying to login which in this case will not work. Or?

tgalal avatar Dec 13 '14 23:12 tgalal

Ok.. how my stack could pass data to the layer?

kwiiby avatar Dec 14 '14 00:12 kwiiby

ahh, in stack using also self.setProp, and then in a layer use self.getProp to get it

tgalal avatar Dec 14 '14 00:12 tgalal

Stack: self.stack.setProp('myprop', 'value')

Layer:

class EchoLayer(YowInterfaceLayer):
    def __init__(self):
        super(EchoLayer, self).__init__()
        print self.getProp('myprop')

Error: AttributeError: 'EchoLayer' object has no attribute '_YowLayer__stack'

kwiiby avatar Dec 14 '14 00:12 kwiiby

dude, where in my comments do I say self.stack ?

tgalal avatar Dec 14 '14 00:12 tgalal

btw, layer must be added to a stack for this to work, because stack must instantiate the layer

tgalal avatar Dec 14 '14 00:12 tgalal

if u instantiate an echolayer urself it won't work

tgalal avatar Dec 14 '14 00:12 tgalal

Using self.stack.setProp or self.setProp reproduces the same error, I'm using self.stack because it is how the demo EchoStack is..

class YowsupEchoStack(object):
    def __init__(self, credentials):
        layers = (
            EchoLayer,
            (YowAuthenticationProtocolLayer, YowMessagesProtocolLayer, YowReceiptProtocolLayer, YowAckProtocolLayer, YowMediaProtocolLayer),
            YowLoggerLayer,
            YowCoderLayer,
            YowCryptLayer,
            YowStanzaRegulator,
            YowNetworkLayer
        )

        self.stack = YowStack(layers)
        self.stack.setProp('myprop', 'value')
        self.stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, credentials)
        self.stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
        self.stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
        self.stack.setProp(YowCoderLayer.PROP_RESOURCE, YowConstants.RESOURCE)

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

        except AuthError as e:
            print("Authentication Error: %s" % e.message)

kwiiby avatar Dec 14 '14 00:12 kwiiby

YowsupEchoStack is not really a stack but it creates the stack, u can see before calling self.stack, it's actually setting self.stack:

 self.stack = YowStack(layers)

tgalal avatar Dec 14 '14 00:12 tgalal

Ok, I got it, but I still can't to pass data to the layer.. do you have an example? thanks

kwiiby avatar Dec 14 '14 14:12 kwiiby

You already sent an example. In what you've sent has the following line

self.stack.setProp(YowCoderLayer.PROP_RESOURCE, YowConstants.RESOURCE)

If you look at Coder Layer you will find it accessing this property

tgalal avatar Dec 15 '14 04:12 tgalal

Hi... were you able to create an example here.. ! I am stuck... :(

meetsudhirg avatar Dec 17 '14 06:12 meetsudhirg

Hi, I am having this error "NameError: global name 'AuthError' is not defined"

shubham14 avatar Jul 14 '15 09:07 shubham14

I Tried Re-registering,but it made no difference

shubham14 avatar Jul 14 '15 09:07 shubham14

have you imported AuthError on your run.py?

from yowsup.layers.auth import AuthError

-------- Original Message -------- From:Shubham Dash [email protected] Sent:Tue, 14 Jul 2015 06:00:38 -0300 To:tgalal/yowsup [email protected] Subject:Re: [yowsup] pass credentials from layer to stack (#451)

Hi, I am having this error "NameError: global name 'AuthError' is not defined"

— Reply to this email directly or view it on GitHub.

Dl0tt avatar Jul 14 '15 14:07 Dl0tt

Thanks,it worked but I have one more query. This is my code,I am able to send messages but not recieve them,it displays nothing

https://gist.github.com/shubham14/e7fbed7a748965897e69

Please look into it and help, Thanks

shubham14 avatar Jul 14 '15 17:07 shubham14