python

How to use YOWSUP (The python WhatsApp library) in ubuntu

Updated 4/June/2019

Yowsup is a python library that allows you to login and use the WhatsApp service and provides you with all capabilities of an official WhatsApp client, allowing you to create a full-fledged custom WhatsApp client.

yowsup_block

Installation

sudo apt-get update

Prepare the system with the necessary components to Yowsup

sudo apt-get install python-dateutil
sudo apt-get install python-setuptools
sudo apt-get install python-dev
sudo apt-get install libevent-dev
sudo apt-get install ncurses-dev

I’m available for hire!

This is my email link: iamjagjeetubhi@gmail.com

Download the library with the command

git clone git://github.com/tgalal/yowsup.git

Navigate to the folder

cd yowsup

and install the library with the command

sudo python setup.py install

Registration

After installing the library we have to register the device to use WhatsApp. Yowsup comes with a cross platform command-line frontend called yowsup-cli. It provides you with the options of registration, and provides a few demos such as a command line client.

    • First of all create a file vim dexMD5.py
    • Now paste the code from this file.
    • Then save and quit the file.

I’m available for hire!

This is my email link: iamjagjeetubhi@gmail.com

  • Now, Download latest version of WhatsApp from here
  • Copy the Downloaded WhatsApp.apk to current directory.
  • pip install pyaxmlparser
  • Run the command python dexMD5.py WhatsApp.apk
  • You will get the output like
Version: 2.17.344
ClassesDex: OxVSHnBDYNBZmSiYzwF9+A==
  • You have to write that in
    yowsup/env/env_android.py

    (replacing _MD5_CLASSES and _VERSION vars) then run:

  • python setup.py build
  • python setup.py install

WhatsApp registration involves 2 steps. First you need to request a registration code. And then you resume the registration with code you got.

Request a code with command

python yowsup-cli registration --requestcode sms --phone 91xxxxxxxxxx --cc 91 --mcc 222 --mnc 10 -E android

Please add country code as well before mobile no.

Replace with your data ,

cc is your country code in this example 91 is for India,

mcc is Mobile Country Code check your here

mnc is Mobile Network Code check your here

You should receive on your phone a sms message with a code like xxx-xxx

Send a message to request registration with this command, (replace xxx-xxx with code you received)

python yowsup-cli registration --register xxx-xxx --phone 91xxxxxxxxxx --cc 91 -E android

If all goes well, we should get a message like this

{
    "__version__": 1,
    "cc": "91",
    "client_static_keypair": "4LwtAptoy3o7RvZKi4/8**************+8O/1YzTqcWU78M/DK1cDap104G243EkySxN7eQ==",
    "expid": "qsufBg*******GpQV8zNTFg==",
    "fdid": "6a92d996-0c31-****-8bc1-6c8e12990dc8",
    "id": "Sow6yYuOVyGQ******vjVhwiMds=",
    "login": "91**********",
    "mcc": "404",
    "mnc": "88",
    "phone": "91**********",
    "sim_mcc": "000",
    "sim_mnc": "000"
}

Create a file to save your credentials in current directory

I’m available for hire!

This is my email link: iamjagjeetubhi@gmail.com

vim config.json

with the above content.

Ok, we’re ready for the test,

I’m available for hire!

This is my email link: iamjagjeetubhi@gmail.com

yowsup-cli demos --yowsup --config config.json

You can see Yowsup prompt

If type “/help” you can see all available commands

First use the ‘/L’ command for login; to send a message type

/message send 91xxxxxxxxxx "This is a message sent from Command line"

replace xxx with the recipient number

If you respond with a message it will be displayed.

Thanks. 🙂

72 thoughts on “How to use YOWSUP (The python WhatsApp library) in ubuntu”

  1. connected]:/message broadcast 91xxxxxxxxxx “hi”
    [connected]:
    Sent: 1507379830-4
    I am not getting any error and not receive the message

    Like

  2. Hi , i installed it and tried your advices , with successful registration , but when i use the command , yowsup-cli demos –yowsup –config config
    where the config file supplied with my mobile and password , but it still showed ,

    [offline] : /L
    general: Disconnected: Connection Closed

    any further advice ? Thanks.

    Like

  3. i need help to install yowsup api,
    if any can help me intall and teach me how to use i ill pay for this help
    thanks
    whatsapp +923218355022

    Like

  4. Hi,

    Thank you for providing such a clear demonstration.

    I have managed to register (android) however when using yowsup-cli demos I get

    “`general: Login Failed, reason: not-authorized
    Auth Error, reason not-authorized

    or

    “`general: Login Failed, reason: not-authorized
    DEBUG:yowsup.layers.network.layer:Disconnected, reason: Authentication Failure
    Auth Error, reason not-authorized
    “`

    I don’t think I am banned because if I download whatsapp on the handset I registered I can use it to send/receive just fine.

    In env_android.py I have changed _MD5_CLASSES & _VERSION, did you change _KEY too?
    Also in env.py DEFAULT = Android.

    Any suggestions?
    Thanks in advance.

    Like

  5. hm… got strange error on python dexMD5.py WhatsApp.apk:

    Version:
    credBlocks:PAY: IndiaUPIAppActivity onLibraryResult for credentials: 4PAY: IndiaUPIAppActivity onLibraryResult got error: 7PAY: IndiaUPIAppActivity onLibraryResult for resend otp PAY: startShowPinFlow at count: max: 3; showErrorAndFinish#PAY: onRegisterApp got registered: ; showErrorAndFinishinitial#PAY: onGetChallenge got challenge:

    Like

  6. Hi, after I run command yowsup-cli registration –requestcode sms -p 6013375xxxx –cc 60 –mcc 502 –mnc 13 -E android -d, I’m getting error bad_token. Can you help please?

    Like

    1. My mistake. I can get the code and successfully registered. But when I try the next step to login, I get this error;

      [offline]:/L
      general: Login Failed, reason: not-authorized
      Auth Error, reason not-authorized

      Like

      1. Hello friend, I was wondering if you could solve the problem of offline since I still have that problem

        Like

  7. Hi, I have the same problem of Azizyaakup.
    [offline]:/L
    general: Login Failed, reason: not-authorized
    Auth Error, reason not-authorized
    Can you help me, please?

    Like

  8. Thanks a lot for sharing this! Can you please explain how does this method with downloading apk file is different from other solutions like https://github.com/colonyhq/yowsup which do not require apk. Is it better from banning perspective? Would appreciate detailed explanatation since trying to get into field deeper and bans are very critical for many. Thanks in advance

    Like

      1. I congratulate you for such a good tutorial, I wonder if yowsup could solve the problem of offline conection when executing the command / L

        Like

  9. hey, after entering this command “yowsup-cli demos –yowsup –config config” i got following response with error:

    yowsup-cli v2.0.15
    yowsup v2.5.7

    Copyright (c) 2012-2016 Tarek Galal
    http://www.openwhatsapp.org

    This software is provided free of charge. Copying and redistribution is
    encouraged.

    If you appreciate this software and you would like to support future
    development please consider donating:
    http://openwhatsapp.org/yowsup/donate

    Traceback (most recent call last):
    File “/usr/local/bin/yowsup-cli”, line 4, in
    __import__(‘pkg_resources’).run_script(‘yowsup2==2.5.7’, ‘yowsup-cli’)
    File “/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py”, line 750, in run_script
    self.require(requires)[0].run_script(script_name, ns)
    File “/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py”, line 1527, in run_script
    exec(code, namespace, namespace)
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/EGG-INFO/scripts/yowsup-cli”, line 368, in
    if not parser.process():
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/EGG-INFO/scripts/yowsup-cli”, line 268, in process
    self.startCmdline()
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/EGG-INFO/scripts/yowsup-cli”, line 296, in startCmdline
    stack = cli.YowsupCliStack(credentials, not self.args[“unmoxie”])
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/demos/cli/stack.py”, line 18, in __init__
    self.stack.setCredentials(credentials)
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/stacks/yowstack.py”, line 157, in setCredentials
    self.getLayerInterface(YowAuthenticationProtocolLayer).setCredentials(*credentials)
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/auth/layer_interface_authentication.py”, line 5, in setCredentials
    self._layer.setCredentials((phone, password))
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/auth/layer_authentication.py”, line 46, in setCredentials
    self._credentials = self.__getCredentials(credentials)
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/auth/layer_authentication.py”, line 41, in __getCredentials
    password = base64.b64decode(pb64)
    File “/usr/lib/python2.7/base64.py”, line 78, in b64decode
    raise TypeError(msg)
    TypeError: Incorrect padding

    i’m not good in coding so i did not get this error. can you help me please?

    Like

  10. Hello, I followed all the steps but returned the following:
    yowsup marcus$ python yowsup-cli registration –requestcode sms –phone 551143496189 –cc 55 –mcc 724 –mnc 06 -E android
    yowsup-cli v2.0.15
    yowsup v2.5.7

    Copyright (c) 2012-2016 Tarek Galal
    http://www.openwhatsapp.org

    This software is provided free of charge. Copying and redistribution is
    encouraged.

    If you appreciate this software and you would like to support future
    development please consider donating:
    http://openwhatsapp.org/yowsup/donate

    INFO:yowsup.common.http.warequest:{“login”:”551143496189″,”status”:”fail”,”reason”:”bad_param”,”param”:”number”}

    status: fail
    param: number
    reason: bad_param
    login: 551143496189

    Whatsapp version:
    Version: 2.18.62
    ClassesDex: KAtYkYa0lEUyKqfhXtmGhw==

    Where did I go wrong?

    Thanks if you can help me.

    Like

  11. Hi Jagjeet,
    Awesome tutorial and effort. I have implemented the solution but facing an issue. I’m able to send message to only one contact whenever I try to send message to other contact it Yowsup-cli showing help command.

    I’m also getting below error while executing /L – login command and my terminal hangs(using python 2.7)

    [offline]:/L
    Auth: Logged in!
    [connected]:WARNING:axolotl.sessionbuilder:We’ve already setup a session for this V3 message, letting bundled message fall through…
    Traceback (most recent call last):
    File “/usr/local/bin/yowsup-cli”, line 4, in
    __import__(‘pkg_resources’).run_script(‘yowsup2==2.5.7’, ‘yowsup-cli’)
    File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py”, line 742, in run_script
    self.require(requires)[0].run_script(script_name, ns)
    File “/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py”, line 1667, in run_script
    exec(code, namespace, namespace)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/EGG-INFO/scripts/yowsup-cli”, line 368, in
    if not parser.process():
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/EGG-INFO/scripts/yowsup-cli”, line 268, in process
    self.startCmdline()
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/EGG-INFO/scripts/yowsup-cli”, line 297, in startCmdline
    stack.start()
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/demos/cli/stack.py”, line 26, in start
    self.stack.loop(timeout = 0.5, discrete = 0.5)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/stacks/yowstack.py”, line 189, in loop
    asyncore.loop(*args, **kwargs)
    File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py”, line 216, in loop
    poll_fun(timeout, map)
    File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py”, line 156, in poll
    read(obj)
    File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py”, line 87, in read
    obj.handle_error()
    File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py”, line 83, in read
    obj.handle_read_event()
    File “/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/asyncore.py”, line 449, in handle_read_event
    self.handle_read()
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/network/layer.py”, line 102, in handle_read
    self.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/network/layer.py”, line 110, in receive
    self.toUpper(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 79, in toUpper
    self.__upper.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/stanzaregulator/layer.py”, line 29, in receive
    self.processReceived()
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/stanzaregulator/layer.py”, line 52, in processReceived
    self.processReceived()
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/stanzaregulator/layer.py”, line 49, in processReceived
    self.toUpper(oneMessageData)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 79, in toUpper
    self.__upper.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/auth/layer_crypt.py”, line 65, in receive
    self.toUpper(payload)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 79, in toUpper
    self.__upper.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/coder/layer.py”, line 35, in receive
    self.toUpper(node)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 79, in toUpper
    self.__upper.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/logger/layer.py”, line 14, in receive
    self.toUpper(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 79, in toUpper
    self.__upper.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/layer_control.py”, line 44, in receive
    self.toUpper(protocolTreeNode)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 79, in toUpper
    self.__upper.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 194, in receive
    s.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/layer_receive.py”, line 41, in receive
    self.onMessage(protocolTreeNode)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/layer_receive.py”, line 74, in onMessage
    self.handleEncMessage(protocolTreeNode)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/layer_receive.py”, line 90, in handleEncMessage
    self.handleSenderKeyMessage(node)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/layer_receive.py”, line 159, in handleSenderKeyMessage
    self.parseAndHandleMessageProto(encMessageProtocolEntity, plaintext)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/layer_receive.py”, line 188, in parseAndHandleMessageProto
    self.handleConversationMessage(node, m.conversation)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/layer_receive.py”, line 217, in handleConversationMessage
    self.toUpper(messageNode)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 79, in toUpper
    self.__upper.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 194, in receive
    s.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 130, in receive
    recv(node)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/protocol_messages/layer.py”, line 21, in recvMessageStanza
    self.toUpper(entity)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/__init__.py”, line 79, in toUpper
    self.__upper.receive(data)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/interface/interface.py”, line 80, in receive
    self.entity_callbacks[entityType](entity)
    File “/Library/Python/2.7/site-packages/yowsup2-2.5.7-py2.7.egg/yowsup/demos/cli/layer.py”, line 512, in onMessage
    MESSAGE_ID = message.getId()
    UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-6: ordinal not in range(128)

    Thanks

    Like

  12. I have tried with python 3.6. I’m getting below error while login

    [offline]:/L
    general: Login Failed, reason: not-authorized
    Auth Error, reason not-authorized

    I’m on mac system
    Please help
    Thanks

    Like

  13. hello,

    I have install yowsup and registered my mobile no by mistake i removed yowsup directory. so i doing same process again at that time i am not able to register my same mobile
    it gives below response

    INFO:yowsup.common.http.warequest:b'{“status”:”fail”,”reason”:”blocked”,”login”:”91xxxxxxxxxx”}\n’
    status: b’fail’
    reason: b’blocked’

    please help me

    i have to re-registered mobile no again ?

    Like

  14. Good afternoon, I was blocked after sending my first message.
    What I can do for this does not happen.

    INFO: yowsup.common.http.warequest: b ‘{“status”: “fail”, “reason”: “blocked”, “login”: “554196724000”} \ n’
    status: b’fail ‘
    login: b’554196724000 ‘
    reason: b’blocked ‘

    Blak

    Like

  15. Hi,
    I am getting below error
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup# yowsup-cli demos –yowsup –config config
    Traceback (most recent call last):
    File “/usr/bin/yowsup-cli”, line 323, in
    if not parser.process():
    File “/usr/bin/yowsup-cli”, line 227, in process
    self.startCmdline()
    File “/usr/bin/yowsup-cli”, line 249, in startCmdline
    from yowsup.demos import cli
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/demos/cli/__init__.py”, line 1, in
    from .stack import YowsupCliStack
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/demos/cli/stack.py”, line 5, in
    from yowsup.layers.axolotl.props import PROP_IDENTITY_AUTOTRUST
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/__init__.py”, line 1, in
    from .layer_send import AxolotlSendLayer
    File “/usr/local/lib/python2.7/dist-packages/yowsup2-2.5.7-py2.7.egg/yowsup/layers/axolotl/layer_send.py”, line 6, in
    from axolotl.sessioncipher import SessionCipher
    File “build/bdist.linux-x86_64/egg/axolotl/sessioncipher.py”, line 6, in
    ImportError: No module named cryptography.hazmat.primitives.ciphers
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup#
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup#
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup# sudo vim config
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup#
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup#
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup#
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup#
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup#
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup# /message send 919399180125 “This is a message sent from Command line”
    bash: /message: No such file or directory
    root@WINNB0188:/usr/lib/python2.7/dist-packages/yowsup/env/yowsup# /help
    bash: /help: No such file or directory

    Like

  16. while registering I am getting below error .
    please suggest .

    [centos@ip-172-31-22-95 yowsup]$ python yowsup-cli registration –requestcode sms –phone 91(my num ) –cc 91 –mcc 404 –mnc 49 -E android
    yowsup-cli v2.0.15
    yowsup v2.5.7

    Copyright (c) 2012-2016 Tarek Galal
    http://www.openwhatsapp.org

    This software is provided free of charge. Copying and redistribution is
    encouraged.

    If you appreciate this software and you would like to support future
    development please consider donating:
    http://openwhatsapp.org/yowsup/donate

    INFO:yowsup.common.http.warequest:{“login”:”917306377115″,”status”:”fail”,”reason”:”old_version”}

    status: fail
    reason: old_version
    login: (my num)

    Like

  17. After successfully performed all steps when I type the command /L, It shows “general: Disconnected: Connection Closed”, /ping Error: Not connected. What is the issue? Please help

    Like

  18. Hello .
    I had the following error after successful registration and trying the following command :

    yowsup-cli demos –yowsup –config config
    Traceback (most recent call last):

    File “/usr/local/bin/yowsup-cli”, line 4, in
    __import__(‘pkg_resources’).run_script(‘yowsup2==2.5.7’, ‘yowsup-cli’)
    ImportError: No module named ‘pkg_resources’

    Any help ?

    Like

  19. Hello,

    I am getting below error when I run “python dexMD5.py WhatsApp.apk” command.
    Do you have any idea?

    Traceback (most recent call last):
    File “dexMD5.py”, line 12, in
    apk = APK(apkFile)
    File “/usr/local/lib/python2.7/dist-packages/pyaxmlparser/core.py”, line 121, in __init__
    self._apk_analysis()
    File “/usr/local/lib/python2.7/dist-packages/pyaxmlparser/core.py”, line 143, in _apk_analysis
    ap = AXMLPrinter(manifest_data)
    File “/usr/local/lib/python2.7/dist-packages/pyaxmlparser/axmlprinter.py”, line 50, in __init__
    _type = next(self.axml)
    TypeError: AXMLParser object is not an iterator

    Like

Leave a reply to Pitar Cancel reply