I dont have much experience in python, so it might be a stupid question.
Im trying to write to a file in my script, if I run the script from his folder, it works, however if I run it from another folder, I have an error 13 persmission denied
i.e. in cmd :
cd C:\Users\user010\Perforce\Build\LS3\
py Build_jenkins.py
works but
cd C:\Program Files (x86)\Jenkins\workspace\LC3.3 Test\Qt\main
py C:\Users\user010\Perforce\Build\LS3\Build_jenkins.py
doesnt work. I have tried moving the script and the file to a public folder, same error :
Traceback (most recent call last):
File "C:\Users\Public\Documents\Build\LS3\Build_jenkins.py", line 159, in <module>
Variables.Sauvegarder()
File "C:/Users/Public/Documents/Build/LS3/../Common\Variables.py", line 87, in Sauvegarder
gArbre.write( NOM_FICHIER )
File "C:\Python34\lib\xml\etree\ElementTree.py", line 761, in write
with _get_writer(file_or_filename, encoding) as write:
File "C:\Python34\lib\contextlib.py", line 59, in __enter__
return next(self.gen)
File "C:\Python34\lib\xml\etree\ElementTree.py", line 798, in _get_writer
errors="xmlcharrefreplace")
PermissionError: [Errno 13] Permission denied: 'Variables.xml'
The code is Variables.Sauvegarder() in my main file and in Variables :
import xml.etree.ElementTree as ET
gArbre = ET.parse( "Variables.xml" )
def Sauvegarder():
gArbre.write( "Variables.xml")
Edit : important detail I forgot to mention, the file im writing to is located in the script folder (C:/Users/Public/Documents/Build/LS3/../Common\Variables.xml)
To be honest, I'm not sure about Windows computers (for a mac or other linux-based system you'd use sudo), but I would recommend trying to run the command as an administrator (use the runas command plus the name of an account with admin priveledges.) That should hopefully fix the error you're getting.
Related
I have installed exiftool (https://smarnach.github.io/pyexiftool/) and I am able to import the library, but I get the following error when trying to run the test data just to see if it works.
ERROR: test_get_metadata (__main__.TestExifTool)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Program Files\Python36\Lib\site-
packages\pyexiftool\test\test_exiftool.py", line 66, in test_get_metadata
with self.et:
File "C:\Program Files\Python36\lib\site-packages\exiftool.py", line 191, in __enter__
self.start()
File "C:\Program Files\Python36\lib\site-packages\exiftool.py", line 174, in start
stderr=devnull)
File "C:\Program Files\Python36\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files\Python36\lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I also did run the setup code that is in the exiftool folder and still no luck. I think it might be a library issue or path or the (init.py) file, but I've tried several ways and so I'm here to ask if anyone else has a solution or ideas for me to try and fix it.
I'm running Python 3.6.6 and have tried other versions.
(I can run exiftool in command line, but I have encoded BASE64 images that exiftool doesnt work in command line to fully decode.)
Thank you StarGeek! The problem was that I didn't have the exiftool command tool (the separate application of exiftool) in the right PATH env variable. Once I added the application to the PATH env variables i got it to work. Also in the python exiftool code at line 70 it says that you have to have it in the path or direct it to the executable, that I had missed. Thanks again!
I would like to use the Odoo Framework from the shell.
I installed the module "Shell command backport" (technical name: shell), but I couldn't make it work.
$ ./odoo.py shell --addons-path=/opt/odoo_8/src/linked-addons -d database_name
Traceback (most recent call last):
File "./odoo.py", line 160, in <module>
main()
File "./odoo.py", line 157, in main
openerp.cli.main()
File "/opt/odoo_8/src/OCA/OCB/openerp/cli/__init__.py", line 58, in main
for m in module.get_modules():
File "/opt/odoo_8/src/OCA/OCB/openerp/modules/module.py", line 351, in get_modules
plist.extend(listdir(ad))
File "/opt/odoo_8/src/OCA/OCB/openerp/modules/module.py", line 346, in listdir
return map(clean, filter(is_really_module, os.listdir(dir)))
OSError: [Errno 2] No such file or directory: '/opt/odoo8/openerp/addons'
Where is defined the path /opt/odoo8/openerp/addons? I checked this similar question as well.
If I don't write the addons path in the command the error appears again.
I read the answer of this other question, I tried the module and the script option but they didn't work. What should I do to make it work? Any hint would help.
Check your .opererp_serverrc for the user you are executing the command as. In the users home directory you will find this file. There may be reference to the addons_path. The path it appears to be looking for /opt/odoo8/openerp/addons differs from what you have specified in your command. I would check your config files.
I have SSHed from my local machine (a Mac) to a remote machine called “ten-thousand-dollar-bill” as the user “chilge”.
I want to run a Python script in the folder “/afs/athena.mit.edu/c/h/chilge/web_scripts” that generates and saves a .png image to the folder “/afs/athena.mit.edu/c/h/chilge/www/TAF_figures/KORD/1407”. When I run the script from the command line, the image is generated and saved without any issues. When I run the script as cron job, though (the crontab resides in “/afs/athena.mit.edu/c/h/chilge/cron_scripts”), I get the following error:
Traceback (most recent call last):
File "/afs/athena.mit.edu/user/c/h/chilge/web_scripts/generate_plots.py", line 15, in
save_taffig(taf,fig)
File "/afs/athena.mit.edu/user/c/h/chilge/web_scripts/plotting.py", line 928, in save_taffig
fig.savefig(os.getcwd()+'/'+savename+'.png')
File "/usr/lib64/python2.7/site-packages/matplotlib/figure.py", line 1084, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/backend_bases.py", line 1923, in print_figure
**kwargs)
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 443, in print_png
filename_or_obj = file(filename_or_obj, 'wb')
IOError: [Errno 13] Permission denied: '/afs/athena.mit.edu/user/c/h/chilge/www/TAF_figures/KORD/1407/140723-1200_AMD_140723-1558.png'
I believe I’ve correctly changed the permissions of all of the necessary directories, but I’m still getting this error. I am not sure why the script would run fine from the command line, but fail when I try to run the script as a cron job.
(Also, I’m not sure if this will be relevant, but don’t have sudo permissions on the remote machine.)
Maybe an other software opens the file which you want to overwrite?
I see the following error in the log file:
Exception in thread Thread-1:
Traceback (most recent call last):
File "threading.pyc", line 486, in __bootstrap_inner
File "launcher\taskthread.pyc", line 65, in run
File "subprocess.pyc", line 594, in __init__
File "subprocess.pyc", line 816, in _execute_child
WindowsError: [Error 5] Access is denied
WindowsError: [Error 5] Access is denied
In Windows I used to see this error myself after installing Google App Engine SDK for PHP. This error occured when gae could not find the PHP executable.
The thing was I was specifying the absolute path to the folder that contained php-cgi.exe, leaving out the name of the executable php-cgi.exe! I solved this problem by adding the name of tyhe executable as well. So you might want to take a look again at your absolute path and make corrections.
from the docs:
Start the web server with the following command, giving it the path to
your project directory:
google_appengine/dev_appserver.py --php_executable_path=absolute-path-to-php-cgi.exe myproject/
Hope it helps,
I have an xml file on a windows network drive that I am trying to read and write to. I have full permission to edit the file normally (in gedit or anything), but when I attempt to parse the xml file in python, I get a permissions error. Any ideas?
Here is an example of what I am trying to do:
from xml.etree import ElementTree as ET
file = "/directory/to/xml/file"
nfo = ET.parse(file)
I then read info from the file and write to the file. It hangs up when trying to write to the file (even though when I use gedit, I can write to the file fine)
the error I get is:
Traceback (most recent call last):
File "parser.py", line 277, in <module>
nfo.write(file)
File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 803, in write
file = open(file_or_filename, "wb")
IOError: [Errno 13] Permission denied: '/directory/to/xml/file'
are you sure that gedit does not ignore lack of write permission if you're the file owner? vim can do that, and maybe gedit too? I'd start with simple ls -l /directory/to/xml/file.
you can always do strace -f /path/to/your_program.py, that should give you more info on what is actually being attempted by python runtime.