spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.25k stars 1.6k forks source link

Spyder cannot save the script to a mapped network drive due to permission errors #17799

Open miklos-zoldi opened 2 years ago

miklos-zoldi commented 2 years ago

Issue Report Checklist

Problem Description

I open a new script in Spyder editor and then go to File -> Save as... to save my file. I can save it onto my local drive normally. However, if I select a mapped network drive a network error occurs.

Spyder can reach the network drive - I can load/save a text file from/to the network drive, the only thing which throws an error if I try to save the script itself via Save as. Interestingly, saving without using the Save as function (i.e., modifying a script loaded into Spyder from the network drive, and then simply running it or saving it via ctrl+s) also works. I often get the very same error message if I just try to drag and drop a script from the network drive to Spyder's editor (unfortunately this does not happen always, so I cannot reproduce, and restarting Spyder usually solves this issue, unlike the Save as issue).

This issue is very similar to that of https://github.com/spyder-ide/spyder/issues/14660, but the workaround suggested there (downgrading Spyder to the version 4.2.1) does not solve it. The mapped drive is a Geode-Project space (https://kb.iu.edu/d/aoyg).

What steps reproduce the problem?

  1. Open Spyder
  2. Click on File -> New file
  3. Click on Save as... and select a mapped network drive

What is the expected output? What do you see instead?

Saving the script onto the chosen file path. A network error occurs instead.

Paste Traceback/Error Below (if applicable)

Traceback (most recent call last):
  File "C:\Users\mzoldi\Anaconda3\lib\ntpath.py", line 647, in realpath
    path = _getfinalpathname(path)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'L:\\mzoldi\\untitled0.py'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\plugin.py", line 2305, in save_as
    if editorstack.save_as():
  File "C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 1997, in save_as
    ao_index = self.has_filename(filename)
  File "C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 1501, in has_filename
    if fixpath(filename) == fixpath(finfo.filename):
  File "C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 1499, in <lambda>
    fixpath = lambda path: osp.normcase(osp.realpath(path))
  File "C:\Users\mzoldi\Anaconda3\lib\ntpath.py", line 651, in realpath
    path = _getfinalpathname_nonstrict(path)
  File "C:\Users\mzoldi\Anaconda3\lib\ntpath.py", line 601, in _getfinalpathname_nonstrict
    path = _getfinalpathname(path)
OSError: [WinError 59] An unexpected network error occurred: 'L:\\mzoldi'

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0          :  1.4.0 (OK)
chardet >=2.0.0               :  4.0.0 (OK)
cloudpickle >=0.5.0           :  2.0.0 (OK)
cookiecutter >=1.6.0          :  1.7.3 (OK)
diff_match_patch >=20181111   :  20200713 (OK)
intervaltree >=3.0.2          :  3.1.0 (OK)
IPython >=7.6.0               :  8.2.0 (OK)
jedi >=0.17.2;<0.19.0         :  0.18.1 (OK)
jsonschema >=3.2.0            :  4.4.0 (OK)
keyring >=17.0.0              :  23.4.0 (OK)
nbconvert >=4.0               :  6.4.4 (OK)
numpydoc >=0.6.0              :  1.2 (OK)
paramiko >=2.4.0              :  2.8.1 (OK)
parso >=0.7.0;<0.9.0          :  0.8.3 (OK)
pexpect >=4.4.0               :  4.8.0 (OK)
pickleshare >=0.4             :  0.7.5 (OK)
psutil >=5.3                  :  5.8.0 (OK)
pygments >=2.0                :  2.11.2 (OK)
pylint >=2.5.0;<2.10.0        :  2.9.6 (OK)
pyls_spyder >=0.4.0           :  0.4.0 (OK)
pylsp >=1.2.2;<1.3.0          :  1.2.4 (OK)
pylsp_black >=1.0.0           :  None (OK)
qdarkstyle =3.0.2             :  3.0.2 (OK)
qstylizer >=0.1.10            :  0.1.10 (OK)
qtawesome >=1.0.2             :  1.0.3 (OK)
qtconsole >=5.1.0             :  5.3.0 (OK)
qtpy >=1.5.0                  :  2.0.1 (OK)
rtree >=0.9.7                 :  0.9.7 (OK)
setuptools >=49.6.0           :  61.2.0 (OK)
sphinx >=0.6.6                :  4.4.0 (OK)
spyder_kernels >=2.1.1;<2.2.0 :  2.1.3 (OK)
textdistance >=4.2.0          :  4.2.1 (OK)
three_merge >=0.1.1           :  0.1.1 (OK)
watchdog >=0.10.3             :  2.1.6 (OK)
zmq >=17                      :  22.3.0 (OK)

# Optional:
cython >=0.21                 :  0.29.28 (OK)
matplotlib >=2.0.0            :  3.5.1 (OK)
numpy >=1.7                   :  1.21.5 (OK)
pandas >=1.1.1                :  1.4.2 (OK)
scipy >=0.17.0                :  1.7.3 (OK)
sympy >=0.7.3                 :  1.10.1 (OK)
dalthviz commented 2 years ago

Hi @miklos-zoldi ! I did some tests but I was unable to reproduce this error :/

Not totally sure if it could be related to this but the Windows machine where I'm testing has Windows 10 21H1.

From the traceback, seems like this is happening when calling os.path.realpath(path) and maybe could be related to the character \ which escaped becomes \\. Could you try to replace in your local installation the line 1499 at C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py from this:

fixpath = lambda path: osp.normcase(osp.realpath(path))

to this:

fixpath = lambda path: osp.normcase(osp.realpath(path.replace('\\', '/')))

Let us know if that helps

miklos-zoldi commented 2 years ago

Hi @dalthviz , thanks for your help! I replaced the above mentioned line with your suggestions but the error still persists.

dalthviz commented 2 years ago

Do you still see have the same traceback @miklos-zoldi ? When changing the line you restarted Spyder, right? Also, is there any possibility for you to test the access to the mapped network drive from a different computer (to check if are able to reproduce this outside of your current setup). Let us know!

miklos-zoldi commented 2 years ago

Hi @dalthviz! Yes, I restarted Spyder after changing the line. I also tried saving to the mapped network drive from a different computer and could reproduce this error message. Although on this different computer an older version of Spyder (4.2.5) was installed, but the Qt/PyQt5 versions are the same as on mine.

dalthviz commented 2 years ago

Thanks for testing @miklos-zoldi :+1: Thinking about this maybe we could check if using pathlib improves things here. Could you change again the line for something like this?:

from pathlib import Path
fixpath = lambda path: osp.normcase(Path(path).resolve())
miklos-zoldi commented 2 years ago

Hi @dalthviz! I tried the new suggestion - now the error message is a bit different:

Traceback (most recent call last): File "C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\plugin.py", line 2305, in save_as if editorstack.save_as(): File "C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 1998, in save_as ao_index = self.has_filename(filename) File "C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 1502, in has_filename if fixpath(filename) == fixpath(finfo.filename): File "C:\Users\mzoldi\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 1500, in fixpath = lambda path: osp.normcase(Path(path).resolve()) File "C:\Users\mzoldi\Anaconda3\lib\pathlib.py", line 1181, in resolve s = self._flavour.resolve(self, strict=strict) File "C:\Users\mzoldi\Anaconda3\lib\pathlib.py", line 206, in resolve s = self._ext_to_normal(_getfinalpathname(s)) OSError: [WinError 59] An unexpected network error occurred: 'L:\mzoldi'

dalthviz commented 2 years ago

Interesting, @miklos-zoldi do you have permissions to write over that path (L:\mzoldi) from the Windows explorer? Also, what happens if you try to change the same line to only use os.path.normcase? So something like:

fixpath = lambda path: osp.normcase(path)
miklos-zoldi commented 2 years ago

Yes, I have permission to write over this path from Windows Explorer. Changing the line to the above mentioned one will result in a pop-up window with the title: Save Error: Unable to save file 'intitled0.py'; Error message: [WinError 6] The handle is invalid: 'L:\mzoldi'

ccordoba12 commented 2 years ago

@miklos-zoldi, please post the full error to see where it's coming from.

miklos-zoldi commented 2 years ago

Hi @ccordoba12! The previous errors popped up the Issue reporter window where I could see the Traceback when showing the details. However, if I change the line in editor.py to the above mentioned one, now this Issue reporter window will not pup up, only the image attached below. I do not know how can I retrieve the traceback in this situation. If I close the window/or click on OK, nothing will be written into the IPython Console. unable

dalthviz commented 2 years ago

Thanks for the info @miklos-zoldi my guess is that we need to improve the error dialog you mention above to catch the error you have and also let users know that they probably need to check the write permitions over the current working directory to be able to save files.

As a workaround, could you change your Spyder's current working directory (you can change it from the toolbar at the top-rigth) to a folder in your mapped drive where you know you have write permissions and use it to save your files? Let us know if that helps!

miklos-zoldi commented 2 years ago

Thanks @dalthviz for the suggestions! Now I have permission to every folder on the network drive, but none of it works when saving the script via Spyder's Save as function. If I create a .txt file with some content in Spyder, I can save that .txt file into the very same folder which throws the error message when trying to save the script into that folder.

Right now the workaround I have is that during the day I work on my hard drive and at the end of the day I just copy all the scripts back to the network drive. (Of course, this is not ideal, lets say I forget to do this, and then I want to remotely access my files on the network via vpn, but there I will not have the latest versions of my scripts).

dalthviz commented 2 years ago

Do you use the VPN also to connect to the network drive? And yes that is not quite usable :/ Could you revert the changes done to the editor.py please? (to see if the same initial error persists even when you changed the permissions over the mapped network drive folders). I'm not totally sure what else could be causing the problem, sorry. However, I will try to replicate this by mapping a read-only network drive :+1:

Baugus commented 1 year ago

Just for the reference, I appear to be having a similar error. I have Spyder 5.3.3 loaded via conda into its own env. I have a mapped drive "S:", which is a Citrix Sharefile server connected to my computer via Citrix Files. I have full Admin permissions (write, read, edit) for the relevant directories of the mapped drive.

I can open a python script that exists on the mapped drive, I can use the terminal in Spyder to create a .txt file and save it to the mapped drive, but I cannot save a script or use "save as" to save a script to the mapped drive. One distinction between @miklos-zoldi 's error and mine is that I am not able to use ctrl+s to save the file (which if I read correctly, @miklos-zoldi was able to do).

Have there been further developments on this error? Any workarounds other than saving a shadow copy of the script locally? Spyder save issue

Spyder version

miklos-zoldi commented 1 year ago

Hi @Baugus, you have the very same issue then! Unfortunately, there was no improvement, I still use this shadow copy workaround, which is not really convenient.

If I open a new script in the terminal, neither Save As..., nor ctrl+s will work for me when trying to save onto the network drive.

What works sometimes is that I drag and drop a script from the network drive to Spyder's terminal, edit it, and save it via ctrl+s. Other times this will throw the very same error message I originally posted, and other times even the drag and drop will result in the error message. I could not figure it out why it works at some cases but not in other cases.

HZcohort commented 1 year ago

For me, the specific WinError code is 1005 when calling os.path.realpath function. This windows error code is not in the list of "allowed_winerror" in _getfinalpathname_nonstrict function of ntpath.py. So I just added 1005 at the end of "allowed_winerror", and the issue is solved.