import sys import dbus import os def write_file(): fp = open('/etc/fonts/fonts.conf', 'a') fp.write("i have wrote") fp.close if __name__ == "__main__": print "calling wrtie file" #Call the D-Bus method to request PolicyKit authorization: session_bus = dbus.SessionBus() policykit = session_bus.get_object('org.freedesktop.PolicyKit.AuthenticationAgent', '/') if(policykit == None): print("Error: Could not get PolicyKit D-Bus Interface\n") granted = policykit.ObtainAuthorization("test.org.gnome.lirc-properties.mechanism.configure", (dbus.UInt32)(0), (dbus.UInt32)(os.getpid())) print granted if granted: write_file() else: print "no access"