pass credentials from layer to stack
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'
self.setProp instead of self.YowInterfaceLayer.setProp
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
no you don't know much about python import YowAuthenticationProtocolLayer first
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?
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?
Ok.. how my stack could pass data to the layer?
ahh, in stack using also self.setProp, and then in a layer use self.getProp to get it
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'
dude, where in my comments do I say self.stack ?
btw, layer must be added to a stack for this to work, because stack must instantiate the layer
if u instantiate an echolayer urself it won't work
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)
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)
Ok, I got it, but I still can't to pass data to the layer.. do you have an example? thanks
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
Hi... were you able to create an example here.. ! I am stuck... :(
Hi, I am having this error "NameError: global name 'AuthError' is not defined"
I Tried Re-registering,but it made no difference
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.
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