'Open Whatsapp Windows app directly from python program using url

According to this FAQ page of Whatsapp on How to link to WhatsApp from a different app

Using the URL

whatsapp://send?phone=XXXXXXXXXXXXX&text=Hello

can be used to open the Whatsapp app on a Windows PC and perform a custom action.

It does work when it is opened in a browser. The URL opens Whatsapp installed and composes the message(parameter:text) for the given contact(parameter:phone)

I want to open the Whatsapp application directly using python script without the intervention of browser in between

I have tried using request and urlib, but they don't consider it as a valid schema for URL as it does not have a http:// or https:// instead it has whatsapp://.

requests.exceptions.InvalidSchema: No connection adapters were found for 'whatsapp://send'

Is there a library in python that would open the associated applications directly based on the URL.

P.S. I know the page is for Iphone but the link works perfectly on windows browser. Just need to know if that can be used.

Working with Python 3.7.9 on Windows 10



Solution 1:[1]

If you want to just open WhatsApp Beta or WhatsApp of Microsoft store You can go with this:

import os
os.system("start whatsapp://send?phone=XXXXXXXXXX")

OR **If you use WhatsApp Desktop (.exe) so, you can simply go with this:-

import os
os.startfile(r" PATH TO WHATSAPP.EXE ")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 athrvvv