0

I am using Raspberry Pi4 Model B with buster os in it. I am trying to write a python script for running the webpage at bootup. On entering sudo nano /etc/xdg/lxsession/LXDE-pi/autostart in the terminal and adding @chromium-browser --start-fullscreen --start-maximized https://teams.microsoft.com/ at the last line I can see the webpage at boot. But the problem is I need to do this with a python program. Have tried many scripts and it's not working. Every time It's throwing the error saying "No such file or directory: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart". I am attaching the script below. Please help me in solving this I am new to Raspberry Pi.

Without adding sudo nano

conf_file = /etc/xdg/lxsession/LXDE-pi/autostart

def update_url():
       conf_file= '/etc/xdg/lxsession/LXDE-pi/autostart'
       try:
          with open(conf_file, 'w')as file:
             file.write('@chromium-browser --start-fullscreen --start-maximized https://teams.microsoft.com/')

       except Exception as ex:
          print("Cant write dirctory:",ex)
          return 0
       finally:
           pass

Output:

permission denied: /etc/xdg/lxsession/LXDE-pi/autostart

Adding sudo nano

conf_file = sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

def update_url():
       conf_file= 'sudo nano /etc/xdg/lxsession/LXDE-pi/autostart'
       try:
          with open(conf_file, 'w')as file:
             file.write('@chromium-browser --start-fullscreen --start-maximized https://teams.microsoft.com/')

       except Exception as ex:
          print("Cant write dirctory:",ex)
          return 0
       finally:
           pass

Output:

No such file or directory: sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

  • You need to run you .py with sudo, like `sudo python my-test.py` – Philippe Mar 20 '22 at 17:31
  • @Philippe . Actually I have developed a web form for receiving the web url as the input from user .I am saving that user input into a variable named Value1. Like this --> Value1 = form.get('url') . After that I'm trying to open the autostart directory using python itself and write the received user input into it like this --> (f'@chromium-browser --start-fullscreen http:\\{Value1}\') . As you said above I tried putting this flask application in crontab for executing at boot . But I can't get the output . – Abisheik Kumar Mar 21 '22 at 01:39

1 Answers1

0

I have a hunch that Python thinks that "sudo nano" is a directory. Maybe attempt to make it run in the terminal. Read this: Using sudo with Python script

Mikus
  • 29
  • 7