suds Python: Permission denied - python

I have some code that's been untouched since last November, its worked fine this whole time, until now. as far as i know, nothing else has been changed on this host.
The error:
Traceback (most recent call last):
File "/scm/pvcs/scripts/pyscripts/update_scr_20.py", line 115, in <module>
updateSCR(SCR, myDeployer, myDeployerID, myEnv, myEnvID, deployTime)
File "/scm/pvcs/scripts/pyscripts/update_scr_20.py", line 33, in updateSCR
client = Client(url=SBM_WSDL, location=SBM_ENDPOINT, timeout=180)
File "build/bdist.linux-x86_64/egg/suds/client.py", line 109, in __init__
File "build/bdist.linux-x86_64/egg/suds/cache.py", line 145, in __init__
File "build/bdist.linux-x86_64/egg/suds/cache.py", line 277, in checkversion
File "build/bdist.linux-x86_64/egg/suds/cache.py", line 251, in clear
OSError: [Errno 13] Permission denied: '/tmp/suds/suds-7962357479995671267-document.px'
I've changed the file permissions to 777, still get the same 'permission denied' error.

This error is raised when suds is run in multiuser environment. Your user (using whom you are running a script) must not have an ownership of that directory. Also try turning the cache off or change the cache directory.
Can you share your part of code which is causing the error.? You should catch the exception and see the full error log.

This is essentially a less than perfect design decision on the part of the python soap client. It by default creates a file in a global space (/tmp/suds) that is owned by a single user, and that locks out other users from using the python soap client. If you chmod /tmp/suds/* to allow the world access it will work (what IBM recommends in their OpenStack product) ... or clean up after the use of the client by deleting the garbage it leaves behind.
The soap client ought to have created the suds directory in the users space (under /home/username) so each user would have their own, or if it really ought be a global resource it should have used open access to the file. By doing neither, it probably has caused a lot of time lost by many a user. I'd call it a bug. Something that costs users time and is easily fixed.

Related

Baffling FileNotFoundError on Windows

The problem that I'm having is frankly baffling. I was doing some python coding, come back the next day, and without changing anything, the code stopped working, giving a FileNotFoundError. I've whittled it down to a laughably simple minimum code to produce the error.
f = open('positions.tsv','w')
Which produces the error
Traceback (most recent call last):
File "c:/Users/mrhel/Documents/GitHub/gas-collisions/test.py", line 1, in <module>
f = open('positions.tsv','w')
FileNotFoundError: [Errno 2] No such file or directory: 'positions.tsv'
I have been scouring the internet for hours for a solution but everything I come across is someone trying to create a file in a folder that doesn't exist or forgetting to set the mode to 'w'. I copied the exact code that this is happening with onto a Linux machine and it runs just fine, it is specifically not working on my Windows 10 machine.
I have tried rebooting the computer, which doesn't work either. Why would this simple line of code not work specifically on Windows?
Edit:
How I run the code is either python test.py or C:/Users/mrhel/AppData/Local/Microsoft/WindowsApps/python3.8.exe c:/Users/mrhel/Documents/GitHub/gas-collisions/test.py
In any case, the expected behavior according to the open() documentation
is that positions.tsv should be created upon calling this function with the 'w' mode.
When I do create the file in advance, I get an error when I try to write to it.
f = open('positions.tsv','w')
f.write('testing')
f.close()
Error:
OSError: [Errno 9] Bad file descriptor
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/mrhel/Documents/GitHub/gas-collisions/test.py", line 3, in <module>
f.close()
OSError: [Errno 9] Bad file descriptor
Edit 2:
I tried creating a file and reading it, and that works as expected. It's specifically writing that isn't working
Edit 3:
So since it runs in another folder, I decided to check for write permissions, and this is what I got. When I check properties of the folder with windows, all users have allow ticked.
>>> os.access('my_folder', os.W_OK)
False
This is clearly a permissions issue, but I'm not sure how to rectify it.
This turned out to be a result of "Controlled Folder Access" in Windows Defender Ransomware Protection. Turning off this feature allows it to function as expected. It's not clear how Ransomware Protection decided that my code is not to be trusted, but for posterity's sake, that is how this was fixed.

Autoreload failed. ModuleNotFoundError : spec not found for the module

[autoreload of R17_Plot_profiles failed: Traceback (most recent call last):
File "/home/jdrevon/anaconda3/lib/python3.7/site-packages/IPython/extensions/autoreload.py", line 244, in check
superreload(m, reload, self.old_objects)
File "/home/jdrevon/anaconda3/lib/python3.7/site-packages/IPython/extensions/autoreload.py", line 378, in superreload
module = reload(module)
File "/home/jdrevon/anaconda3/lib/python3.7/imp.py", line 314, in reload
return importlib.reload(module)
File "/home/jdrevon/anaconda3/lib/python3.7/importlib/__init__.py", line 168, in reload
raise ModuleNotFoundError(f"spec not found for the module {name!r}", name=name)
ModuleNotFoundError: spec not found for the module 'R17_Plot_profiles'
]
This problem occurs in Python 3.7 on Spyder when I modify part of my code and I press F9 to execute some parts of it. Even if I execute my main python file which load every sub-python .py codes I have this error message. However, It does not stop the code from running but the file didn't save the modifications made. This is the first times it happens since I imported the 'R17_Plot_profiles.py' python file.
However in the case where I execute the main profile, I have the previous message but I have also the following one :
Reloaded modules: reconstruct, R2_Spice_Kernels, R4_Offset_Correction, R5_State_Vectors_twoway_v2, R6_Foot_Print, R7_Framework_Conversion,
R8_BendAng_ImpParam_up, R8_BendAng_ImpParam_dn, R9_Avg_BendAng_ImpParam, R10_Altitude_above_Ellipsoid, R11_Refractivity_and_Bending_Radius_v2,
R12a_Electron_Density_up, R12b_Electron_Density_dn, R12_Electron_Density_avg, R13_Neutral_Number_Density,
R14_Pressure_and_Temperature, R16_Errors, R17_Plot_profiles,
R3_Read_L2_Data_v2
So I don't know how to solve the autoreload problem. I've tried to downgrade my IPython version to 7.5 like some people tried and succeed but for me It doesn't change anything.
Edit : It's important to notice that if I restart the kernel, the first execution do not show the error message until I modify directly the python code.
I did few modifications yesterday and it seems to be solved. Since the error occurence started to be random at some points, i'm not sure for 100% but it can maybe solve the issue.
The problem could be came from the use of os.chdir function, I replaced it by specifying the entire path to save my figures until to go to the path using os.chdir and then save my figures in it.
It can maybe produce some conflicts of path and repository to find the python script which is no longer in the path where the script is currently working and therefore can't find it in order to save the modifications.
I keep you informed if at some point the error comes back but for now after some trials the error didn't show up anymore.

jpype._jclass.NoClassDefFoundError: edu/stanford/nlp/python/SUTimeWrapper

I'm trying to use the sutime python wrapper to make a date normalizer, that would convert any temporal information in strings into dates in the format YYYY-MM-DD. I've created a class, with rules over the sutime outputs to convert the sutime outputs into the standard format as mentioned above. The program is working properly on my local machine, but when i try to run it on a server I get the jpype._jclass.NoClassDefFoundError. The server is on ubuntu with python2, while my local has windows, with python3.
I've tried to implement the solutions to a similar problem on this https://sourceforge.net/p/jpype/discussion/379372/thread/689d7a9b/ forum, but i'm not sure if i was able to implement these soultions correctly. I've also checked that sutime supports both python3 and python2
I think the issue is with jpype or with the sutime library.
This is the traceback that i got
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "date_normalizer.py", line 38, in __init__
self.sutime = SUTime(jars=self.jar_files, mark_time_ranges=mark_time_ranges)
File "/home/bridgei2i/.local/lib/python2.7/site-packages/sutime/sutime.py", line 57, in __init__
'edu.stanford.nlp.python.SUTimeWrapper')
File "/home/bridgei2i/.local/lib/python2.7/site-packages/jpype/_jclass.py", line 130, in __new__
return _JClassNew(args[0], **kwargs)
File "/home/bridgei2i/.local/lib/python2.7/site-packages/jpype/_jclass.py", line 213, in _JClassNew
javaClass = _jpype.PyJPClass(arg)
jpype._jclass.NoClassDefFoundError: edu/stanford/nlp/python/SUTimeWrapper
Seems likely that the jar file holding edu/stanford/nlp/python/SUTimeWrapper was not found on the server. The specific code that failed was a call to JClass('edu.stanford.nlp.python.SUTimeWrapper') which is a request to load a class from a jar. I would recommend checking the classpath and configuration on the server.
Likely causes are (in order of likelihood)
jar file is not located in the classpath on the server.
The jar file is compiled with a JDK which is newer than runtime environment (though this should generate a different exception).
Some jar file that the class depends on is missing or has the wrong version. (this should produce a different classname in the exception, so it is unlikely.)
A dll for a native portion the jar file is missing or has an incorrect architecture. (rare)
Assuming the jar file is on the server, I would recommend checking the initialization in which the JPype startJVM call is made to see if the path to the jar was correct. It is also possible to examine the loaded classpath using print(jpype.java.lang.System.getProperty('java.class.path')) to see if there is a difference between your local and server machine.
thank you, as you said:Some jar file that the class depends on is missing or has the wrong version. (this should produce a different classname in the exception, so it is unlikely.)

"Windows Error: provider DLL failed to initialize correctly" on import of cgi module in frozen wxpython app

I have a user of a frozen wxpython app that gets the appended screenshot.
The error message is "Windows Error: provider DLL failed to initialize correctly"
A screenshot taken from a paused video is the only way I could get this error message from them because the whole thing disappears instantly (including this DOS window created to capture stderr, where this message is appearing). IE python is dieing before it even really gets going.
The traceback points to my code at controller.py line 14.
This line is
import cgi
For some reason, it seems that cgi is calling random during import (why would that be?) and for some reason this is failing for some DLL reason.
Any clues?
Note 1: this app works fine for hundreds of other Windows and Mac users. So it's as if I'm not supplying something that is not on only this user's machine for some reason.
Note 2: the executable is created using bbfreeze, with the following config:
f = Freezer(distdir = distdir,
includes = ['wx.lib.pubsub.core.kwargs.*',
'wx.lib.pubsub.core.*',
'dbhash',
'platform']
)
I'm not sure what else I'd put in here. 'cgi'? 'random'?
For me, the exact error message was:
WindowsError: [Error -2146893795] Provider DLL failed to initialize correctly
with a trace such as:
File "C:\Dev\Python\python-2.7.11\lib\tempfile.py", line 35, in <module>
from random import Random as _Random
File "C:\Dev\Python\python-2.7.11\lib\random.py", line 885, in <module>
_inst = Random()
File "C:\Dev\Python\python-2.7.11\lib\random.py", line 97, in __init__
self.seed(x)
File "C:\Dev\Python\python-2.7.11\lib\random.py", line 113, in seed
a = long(_hexlify(_urandom(2500)), 16)
WindowsError: [Error -2146893795] Provider DLL failed to initialize correctly
And what solved it for me was a comment from http://bugs.python.org/issue1384175 (http://bugs.python.org/msg248947), saying the following:
This happened at a call to `os.urandom` for me.
This was in a subprocess.
The bug for me was that I called `_subprocess.CreateProcess`
with an `env_mapper = {'foo': 'bar'}`. The fix:
env_mapper = os.environ.copy()
env_mapper.update({'foo': 'bar'})
I think the minimal solution is to include the SYSTEMROOT environment variable in the Python subprocess.
I have seen the problem when trying to load os.urandom:
self._authkey = AuthenticationString(os.urandom(32))
WindowsError: [Error -2146893795] Provider DLL failed to initialize correctly
It turns out that the _PyOS_URandom on Windows relies on the SYSTEMROOT environment to be set. See: http://bugs.python.org/issue1384175#msg248951 for a detailed explaination
This seems to occur somewhere inside os.urandom and is probably caused by some missing or incorrect environment variables. In particular it happens if the environment is too long.
If you are starting Python from a shell, open a new shell and try again. If the problem persists, check if there are unusually many environment variables
If you are starting Python from another process, check if the proces environment is set up correctly. I found that this is often not the case for processes run by Apache's CGI module.
if you are starting Python as a CGI process, then you may want to consider better alternatives, such as mod_wsgi.

How to port a Python application to Linux that works fine in Windows

I am having trouble porting a working, Windows Python application to Linux. I am having some problems, because I did not write the code and am just learning Python. I am having trouble fixing the issues that it keeps throwing up. So here is a kind of error that right now I am stuck with
Traceback (most recent call last):
File "alpha_beta", line 237, in <module>
main()
File "alpha_beta", line 185, in main
ABCCmd()
File "alpha_beta.py", line 74, in ABCCmd
File "C:\softs\Python\Lib\shutil.py", line 80, in copy
File "C:\softs\Python\Lib\shutil.py", line 47, in copyfile
IOError: [Errno 13] Permission denied: '/myPath/XFiles.bin.addr_patched
Any pointers on how to fix it will be much appreciated
Edit:
1) What I mean by I am stuck is, the traceback of the error goes to C:\softs\Python\Lib but actually I am currently executing this code in Ubuntu. Why would the traceback reference to windows library
2) Another thing that bothers me is it says there is an IOError.But when I try to add permission for the denied one it gives me a chmod: changing permissions of /myPath/xFiles.bin.addr_patched': Operation not permitted
Edit 2:
I had commented out a module because I thought it wasn't very useful. Since Now I am anyway discussing the porting issues, I thought I can bring up this additional problem as well since I think the issue is the same and the fix should be similar. On including #pdb module in the python code, I get the following error
traceback (most recent call last):
File "alpha_beta", line 6, in <module>
import pdb
File "C:\softs\Python\Lib\pdb.py", line 14, in <module>
File "C:\softs\Python\Lib\pprint.py", line 39, in <module>
ImportError: No module named cStringIO
I looked at the importer_Cache and looks like this
'': None, '/usr/lib/python2.6/plat-linux2': None, '/usr/lib/python2.6/': None
'/usr/lib/pymodules/python2.6/gtk-2.0': None, '/usr/lib/python2.6/lib-tk': None,
'/usr/lib/python2.6/lib-old': <imp.NullImporter object at 0x7f1269048070>, '/usr/
/python2.6/dist-packages/gtk-2.0': None, '/usr/lib/python2.6/dist-packages/PIL': None,
'/usr/local/lib/python2.6/dist-packages': None, '/usr/lib/python2.6/dist-packages':
None
*SOLVED : There was a weird wrapper in the script which was causing the python script to execute from a different location. Still don't understand how though. After modifying my script to just directly execute as python myScript.py it runs fine. Thank you all anyway for the help
The mixture of Windows and Unix style paths in your error messages makes me think that you may have some filenames that are hard coded or manually created using os specific path separators ('\' or '/'). If you can figure out where the gOptions.inputTf and gWorkingTfFile values are assigned you should look into using os.path.join to help you use the correct paths.
from os.path import join
file = join('A', 'B')
# 'A/B' on unix systems
# 'A\B' on windows systems

Categories