Permission error 13 Python 3.5.2 - python

I have a problem opening a file with Python script in windows 10.
What I do is next:
I open my script as administrator in which create a new directory in the route:
C:\ProgramData\New_folder
Inside that folder I create a txt file:
C:\ProgramData\New_folder\log.txt
After that the program put some text in the log.txt and finish.
Now I have to open the script normally not as admin and when the program start it launch an permission error 13 in the following line of code.
dirLog = 'C:\ProgramData\New_folder\log.txt'
output = open(dirLog, "a")
I really don't know what is happening here because I check the file created and it has read and write permissions.
it's of vital importance open the script as admin just the first time, the rest just normally.

This might be caused because of the level of permission that the folder is set at. There is a possible fix for this, but it could cause security issues in the future as far as permissions for that folder go. If you can afford to change the permission level of the folder, try this: navigate to ProgramData, right click on the folder, click 'Properties', then hit the 'Security' tab at the top, then check the permissions for users. If the read permission is set off, turn it on. Otherwise, try enabling the write permission.

Related

Crontab errors while running python program

I wrote a python program that checks a website for new posts, saves a log to a text file and sends me a text message if there is one. I am trying to run this every 5 minutes in a crontab. I am running it in a python environment. The cron file I used:
{*/5 * * * * /Users/my/opt/anaconda3/envs/webscrape/bin/python /Users/my/Desktop/Programming/preply_scrape.py > /dev/null 2>&1}
When I try and save this file in the cron editor I get this dialog box:
"“Terminal” would like to administer your computer. Administration can include modifying passwords, networking, and system settings"
and this error:
""/tmp/crontab.FATUtXZE46":0: bad minute
crontab: errors in crontab file, can't install"
I've been messing with crontab for a few day and even tried launchd but can't figure it out. Could this have something to do with file permissions? Any help with this issue would be greatly appreciated.
I was able to figure it my issue. The issue was that I had to give full disk access to the folder my python programmed was stored and cron. On Mac go to system preference -> Security & Privacy -> Full disk access (on the left side panel). Click on the lock and enter your password to make changes. Click on the plus sign, browse to application -> utilities and find cron. Do the same for your file path.

Cannot get Perforce Triggers to work properly

Been trying to get this working all day, and i just can't figure out why its not working.
Trying to implement a simple trigger to run when the user submitted a file.
example in the .tmp file:
hello_trigger change-submit //testDepot/... "python F:/triggers/hello_trigger.py"
when i try to submit a file i get this:
Submit validation failed -- fix problems then use 'p4 submit -c 10199'.
'hello_trigger' validation failed: python: can't open file 'F:/triggers/hello_trigger.py': [Errno 2] No such file or directory
File exists and can be read, so its not a python issue.. same error with a .txt or .bat file.
From what i can gather the problem seems to be coming from the depot line in the trigger.
//testDepot/... fails
//depot/... doesnt fail, but the script is never fired off.
Any suggestions are greatly appreciated.
also testDepot is a stream not sure if that matters.
python: can't open file 'F:/triggers/hello_trigger.py': [Errno 2] No such file or directory
seems pretty clear that the file doesn't exist, at least from the point of view of this trigger command. Some things to double check:
This is running on the server machine, i.e. the place where the p4d service is running. If you have the script on your client machine the Python executable on the server isn't going to be able to find it!
Similarly, this is being run by whatever user is running p4d (on Windows this is usually the SYSTEM user, which may have limited permissions). Does that user have permission to read this path?
Could it be that your version of Python on Windows doesn't know how to handle paths with Unix-style forward slashes? (Many tools will normalize these for you but you shouldn't depend on it!) Try using a valid Windows path, i.e. F:\triggers\hello_trigger.py.

Starting a python file when a computer starts

I am trying to run a python file when my Windows 10 computer starts up. I've already coded the file. It asks for a password and if its incorrect, it shutdown the computer. If the password is correct, it ends the file and lets the user to continue.
I've looked around but all i can see is how to do it with batch files or solutions to do it when a user logged in, im the only one that uses my machine and there is only 1 user
I've heard something about searching for a 'startup' folder but cant find it. Any ideas?
P.s if you know how to get to the start up folder that could help as well
Place your python file in the Startup folder. The folder is located at
C:\Users\<user-name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Make sure you have enabled Show hidden files. The AppData folder is a hidden folder so you won't find it if you don't enable it.

Python: Errors reading/writing file from python executable

I'm writing a Python application that is executable. It reads and writes to a file. The application uses wx for a GUI and has been given the following permissions:
chmod +x app.py
When I load the application from the terminal like so:
./app.py
The application loads and causes no errors.
However, when I double click the app.py file and click 'execute', everything works perfectly except for the reading and writing of this file. This is a major part of the program and causes errors.
I cannot, for the life of me, understand why this is not working.
I have attempted to set it so that it loads as the root user each time with no luck. I have also been developing as the root user the entire time, so I shouldn't see any issues.
I am using the default Raspbian OS.
It sounds like you need to modify the permissions of the file to be readable/writable/executable by the user you log into the GUI with. Do some reading on Linux File Permissions and see where that takes you.

How do I add a python script to the startup registry?

I'm trying to make my python script run upon startup but I get the error message windowserror access denied, but I should be able to make programs start upon boot because teamviewer ( a third-party program I downloaded ) runs every time I restart my computer so I know that I should be able to make my program run at startup (I might be doing something different though, so if you could shed some light on what teamviewer is doing differently to get its script to run at startup that would be helpful).
Here is my script
import _winreg, webbrowser
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Run')
_winreg.SetValueEx(key,'pytest',0,_winreg.REG_BINARY,'C:\Users\"USERNAME"\Desktop\test.py')
key.Close()
webbrowser.open('www.youtube.com')
Any input is appreciated.
import webbrowser
webbrowser.open('www.youtube.com')
Get rid of all of that _winreg stuff. Instead, you (assuming double-clicking on a py file opens the console) should simply place it in your startup folder (C:\Users\yourusername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup on Windows 7, and C:\Documents and Settings\yourusername\Start Menu\Programs\Startup in XP). This works because Windows tries to open all files in the startup folder, and if Python opens PYs by default, Windows will open the Python console. Try restarting, that should work.
Baboon:
I am a little late posting, but you seem to have left off the sam at the end of your code here.
When you open a key you need to add the user rights, if you do not _winreg defaults to "READ":
Here is a snippet from the python site
http://docs.python.org/2/library/_winreg.html#access-rights
sam is an integer that specifies an access mask that describes the desired security access for the key. Default is KEY_READ. See Access Rights for other allowed values.
Here is the code corrected:
import _winreg, webbrowser
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,'Software\Microsoft\Windows\CurrentVersion\Run',_winreg.KEY_SET_VALUE)
_winreg.SetValueEx(key,'pytest',0,_winreg.REG_BINARY,'C:\Users\"USERNAME"\Desktop\test.py')
key.Close()
webbrowser.open('www.youtube.com')

Categories

Resources