import os
import sys
euid = os.geteuid()
if euid != 0:
    print('Script not started as root. Running sudo..')
args = ['sudo', sys.executable] + sys.argv + [os.environ]
os.execlpe('sudo', *args)
print('Running. Your euid is', euid)
authentication in python script to run as root