-1

i have one python script send message to my phone using pywhatkit

it can run flawlessly on geany IDE.but when i invoke from terminal like sudo python3 /home/pi/Desktop/pyf/whatsappsend.py it run in terminal but it doesn't open whatsapp web and send message.

the script as follow

#!/usr/bin/env python
# -*- coding: utf_8 -*-
import pywhatkit
import datetime
import time

from time import strftime,localtime from time import strftime,gmtime

while True: print('running')

dt_gmt = strftime("%Y-%m-%d %H:%M:%S", localtime())

print(dt_gmt) 
time_only = datetime.datetime.now().time()
pywhatkit.sendwhatmsg_instantly("+65XXXXXXX", str("hello")+str(dt_gmt), 30, True, 10)
time.sleep(60)

pls help me how to make it run on terminal as i want to put in on crontab later on.

Thanks in advance.

Myo

Milliways
  • 59,890
  • 31
  • 101
  • 209

1 Answers1

0

If you are planning to run python3 use:-

#!/usr/bin/env python3

#!/usr/bin/env python is python2 in most OS.

It may not make any difference in Bullseye, but it still doesn't hurt to do it properly.

Why are you using sudo. If the code runs it is almost certainly unnecessary.

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • now it get another error without sudo is permission denied with open("PyWhatKit_DB.txt", "a", encoding="utf-8") as file: PermissionError: [Errno 13] Permission denied: 'PyWhatKit_DB.txt' – sayagyi myo Nov 17 '21 at 06:38
  • permission problem fixed by chmod to that txt file .ok again .thanks mr milliways. – sayagyi myo Nov 17 '21 at 06:48