When I run your sample application I get:
Traceback (most recent call last):
File "run.py", line 13, in <module>
from yowsup.layers.axolotl import YowAxolotlLayer
ImportError: cannot import name YowAxolotlLayer
Is there any working example that I can use?
When I run your sample application I get:
Traceback (most recent call last):
File "run.py", line 13, in
from yowsup.layers.axolotl import YowAxolotlLayer
ImportError: cannot import name YowAxolotlLayer
Is there any working example that I can use?
Probably the sample application is out-dated :
Consider commit "Split up axolotl into 3 layers"
Compare with issue #1611
Hope that it helps.
When I copy the code from #1611 I get this error: yowsup.layers.auth.autherror.AuthError: not-authorized
(BTW, everything works fine when I'm using the cli demos)
Don't use run.py II. @albert-chin is completely right. There is no YowAxolotlLayer anymore. Just use:
stack = stackBuilder\
.pushDefaultLayers(True)\
.push(EchoLayer)\
.build()
Tried it too, still getting yowsup.layers.auth.autherror.AuthError: not-authorized
Which OS are you using? Did you change your install in some way? Which stack and layer code do you use? How did you configure your config? Can you reregister?
I'm using Ubuntu 15.10, and I didn't change neither the config or the install. Here's my full code:
layer.py
from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
from yowsup.layers.protocol_messages.protocolentities import TextMessageProtocolEntity
from yowsup.layers.protocol_receipts.protocolentities import OutgoingReceiptProtocolEntity
from yowsup.layers.protocol_acks.protocolentities import OutgoingAckProtocolEntity
class EchoLayer(YowInterfaceLayer):
@ProtocolEntityCallback("message")
def onMessage(self, messageProtocolEntity):
#send receipt otherwise we keep receiving the same message over and over
if True:
receipt = OutgoingReceiptProtocolEntity(messageProtocolEntity.getId(), messageProtocolEntity.getFrom(), 'read', messageProtocolEntity.getParticipant())
outgoingMessageProtocolEntity = TextMessageProtocolEntity(
messageProtocolEntity.getBody(),
to = messageProtocolEntity.getFrom())
self.toLower(receipt)
self.toLower(outgoingMessageProtocolEntity)
@ProtocolEntityCallback("receipt")
def onReceipt(self, entity):
ack = OutgoingAckProtocolEntity(entity.getId(), "receipt", entity.getType(), entity.getFrom())
self.toLower(ack)
run.py
from yowsup.stacks import YowStackBuilder
from layer import EchoLayer
from yowsup.layers.auth import AuthError
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
from yowsup.env import YowsupEnv
credentials = ("phone", "password") # in my code it's my real phone and password
if __name__== "__main__":
stackBuilder = YowStackBuilder()
stack = stackBuilder\
.pushDefaultLayers(True)\
.push(EchoLayer)\
.build()
stack.setCredentials(credentials)
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)) #sending the connect signal
stack.loop() #this is the program mainloop
(Why do you import YowsupEnv?)
I don't think it's a problem with your layer.py.
So, try this as stack.py:
from yowsup.stacks import YowStackBuilder
from layer import EchoLayer
from yowsup.layers.auth import AuthError
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
class YowsupEchoStack(object):
def __init__(self, credentials, encryptionEnabled = True):
stackBuilder = YowStackBuilder()
self.stack = stackBuilder\
.pushDefaultLayers(encryptionEnabled)\
.push(EchoLayer)\
.build()
self.stack.setCredentials(credentials)
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)
Then save this as run.py:
import client
credentials = ("phone", "password")
stack = client.YowsupEchoStack(credentials)
stack.start()
And this as __init__.py:
from .stack import YowsupEchoStack
And put the files in the following folder structure:
\---client
+---__init__.py
+---layer.py
+---stack.py
+---run.py
I hope I didn't forget anything as I did not test this special case, but at least that's a clean way I do. You can also try to copy the logging function out of the demos, but I do not really believe that you get more information about this error there.
I'm still getting Authentication Error: not-authorized
I had the same issue, but after re-registering my account via the yowsup-client it works (I had verified the same account from my phone's client in between, that seem's to have invalidated the yowsup-credentials).
One other thing I confused is that you can't use the same account on the phone and the yowsup-client.
I registered with one account via the yowsup-cli (See https://github.com/tgalal/yowsup/issues/1742) and a second via the whatsapp-android-client. When I now send messages to the yowsup-account from the android-client, I get my own message as a reply from the yowsup-echo-client.
I don't have the same problem. I had the above problem just after I registered via the yowsup-cli
One other issue I came upon yesterday was getting Authentication Error: not-authorized after it had worked for a while. When I checked with the yowsup-cli (with "--requestcode"), I received the reply that I was blocked by the WhatsApp-server. Apparently I have made too many bad requests while debugging or sent to many messages to the same client.
Unless you have already verified, this might also be a cause...?
I verified with SMS, and all worked good
Too bad :-/
I've set it up exactly as @Dargmuesli fleshed out, with the Layer IV from the sample-app and it worked fine (Until I ran into the ban-issue).
Thank you @Dargmuesli the solution you provided works flawlessly!
Most helpful comment
(Why do you import
YowsupEnv?)I don't think it's a problem with your layer.py.
So, try this as stack.py:
Then save this as run.py:
And this as __init__.py:
And put the files in the following folder structure:
I hope I didn't forget anything as I did not test this special case, but at least that's a clean way I do. You can also try to copy the logging function out of the demos, but I do not really believe that you get more information about this error there.