Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filenbmanager.list_dirs fails for Windows user profile directory #5333

Merged
merged 1 commit into from Mar 20, 2014
Merged

Fix filenbmanager.list_dirs fails for Windows user profile directory #5333

merged 1 commit into from Mar 20, 2014

Conversation

cgohlke
Copy link
Contributor

@cgohlke cgohlke commented Mar 12, 2014

Using ipython‑2.0.0‑b1, pyzmq-14.1.0, and tornado‑3.2 on win‑amd64‑py3.4rc3, Windows 8.1, I get FileNotFoundError and PermissionError (below) when starting ipython notebook from within the user profile directory.

On Windows >XP, the users profile directories contain hidden junctions such as NetHood or My Documents for backwards compatibility. Calling os.stat and os.listdir on these junctions may fail with various Exceptions.

The patch fixes these exceptions for me on win‑amd64‑py3.4 (not tested on other platforms).

2014-03-11 22:54:58.751 [NotebookApp] Using existing profile dir: 'C:\\Users\\gohlke\\.ipython\\profile_default'
2014-03-11 22:54:58.751 [NotebookApp] Using MathJax from CDN: http://cdn.mathjax.org/mathjax/latest/MathJax.js
2014-03-11 22:54:58.782 [NotebookApp] Serving notebooks from local directory: C:\Users\gohlke
2014-03-11 22:54:58.782 [NotebookApp] 0 active kernels
2014-03-11 22:54:58.782 [NotebookApp] The IPython Notebook is running at: http://127.0.0.1:8888/
2014-03-11 22:54:58.798 [NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
2014-03-11 22:54:59.085 [NotebookApp] ERROR | Unhandled error in API request
Traceback (most recent call last):
  File "X:\Python34\lib\site-packages\IPython\html\base\handlers.py", line 286, in wrapper
    result = method(self, *args, **kwargs)
  File "X:\Python34\lib\site-packages\IPython\html\services\notebooks\handlers.py", line 75, in get
    dirs = nbm.list_dirs(path)
  File "X:\Python34\lib\site-packages\IPython\html\services\notebooks\filenbmanager.py", line 192, in list_dirs
    if os.path.isdir(os_path) and not is_hidden(os_path, self.notebook_dir)\
  File "X:\Python34\lib\site-packages\IPython\html\utils.py", line 108, in is_hidden
    st = os.stat(path)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\gohlke\\NetHood'
ERROR:tornado.access:{
  "Connection": "Keep-Alive",
  "Accept-Language": "en-US",
  "X-Requested-With": "XMLHttpRequest",
  "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
  "Accept": "application/json, text/javascript, */*; q=0.01",
  "Dnt": "1",
  "Referer": "http://127.0.0.1:8888/tree",
  "Host": "127.0.0.1:8888",
  "Accept-Encoding": "gzip, deflate"
}
ERROR:tornado.access:500 GET /api/notebooks?_=1394603699023 (127.0.0.1) 11.80ms referer=http://127.0.0.1:8888/tree
2014-03-11 22:54:59.093 [NotebookApp] ERROR | Unhandled error in API request
Traceback (most recent call last):
  File "X:\Python34\lib\site-packages\IPython\html\base\handlers.py", line 286, in wrapper
    result = method(self, *args, **kwargs)
  File "X:\Python34\lib\site-packages\IPython\html\services\notebooks\handlers.py", line 75, in get
    dirs = nbm.list_dirs(path)
  File "X:\Python34\lib\site-packages\IPython\html\services\notebooks\filenbmanager.py", line 192, in list_dirs
    if os.path.isdir(os_path) and not is_hidden(os_path, self.notebook_dir)\
  File "X:\Python34\lib\site-packages\IPython\html\utils.py", line 108, in is_hidden
    st = os.stat(path)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Users\\gohlke\\NetHood'
ERROR:tornado.access:{
  "Connection": "Keep-Alive",
  "Accept-Language": "en-US",
  "X-Requested-With": "XMLHttpRequest",
  "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
  "Accept": "application/json, text/javascript, */*; q=0.01",
  "Dnt": "1",
  "Referer": "http://127.0.0.1:8888/tree",
  "Host": "127.0.0.1:8888",
  "Accept-Encoding": "gzip, deflate"
}
ERROR:tornado.access:500 GET /api/notebooks?_=1394603699024 (127.0.0.1) 0.00ms referer=http://127.0.0.1:8888/tree
2014-03-11 23:46:18.002 [NotebookApp] ERROR | Unhandled error in API request
Traceback (most recent call last):
  File "X:\Python34\lib\site-packages\IPython\html\base\handlers.py", line 286, in wrapper
    result = method(self, *args, **kwargs)
  File "X:\Python34\lib\site-packages\IPython\html\services\notebooks\handlers.py", line 75, in get
    dirs = nbm.list_dirs(path)
  File "X:\Python34\lib\site-packages\IPython\html\services\notebooks\filenbmanager.py", line 188, in list_dirs
    dir_names = os.listdir(os_path)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\gohlke\\My Documents'
ERROR:tornado.access:{
  "Connection": "Keep-Alive",
  "X-Requested-With": "XMLHttpRequest",
  "Referer": "http://127.0.0.1:8889/tree/My%20Documents",
  "Accept-Language": "en-US",
  "Dnt": "1",
  "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
  "Accept-Encoding": "gzip, deflate",
  "Host": "127.0.0.1:8889",
  "Accept": "application/json, text/javascript, */*; q=0.01"
}
ERROR:tornado.access:500 GET /api/notebooks/My%20Documents?_=1394606777923 (127.0.0.1) 4.00ms referer=http://127.0.0.1:8
889/tree/My%20Documents
2014-03-11 23:46:18.037 [NotebookApp] ERROR | Unhandled error in API request
Traceback (most recent call last):
  File "X:\Python34\lib\site-packages\IPython\html\base\handlers.py", line 286, in wrapper
    result = method(self, *args, **kwargs)
  File "X:\Python34\lib\site-packages\IPython\html\services\notebooks\handlers.py", line 75, in get
    dirs = nbm.list_dirs(path)
  File "X:\Python34\lib\site-packages\IPython\html\services\notebooks\filenbmanager.py", line 188, in list_dirs
    dir_names = os.listdir(os_path)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\gohlke\\My Documents'
ERROR:tornado.access:{
  "Connection": "Keep-Alive",
  "X-Requested-With": "XMLHttpRequest",
  "Referer": "http://127.0.0.1:8889/tree/My%20Documents",
  "Accept-Language": "en-US",
  "Dnt": "1",
  "User-Agent": "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko",
  "Accept-Encoding": "gzip, deflate",
  "Host": "127.0.0.1:8889",
  "Accept": "application/json, text/javascript, */*; q=0.01"
}
ERROR:tornado.access:500 GET /api/notebooks/My%20Documents?_=1394606777926 (127.0.0.1) 0.00ms referer=http://127.0.0.1:8
889/tree/My%20Documents

@minrk
Copy link
Member

minrk commented Mar 12, 2014

Can you catch OSError instead of Exception?

@jdfreder
Copy link
Member

Also, it looks like this is causing a real failure in the regression tests:

  File "/home/travis/virtualenv/python3.3/lib/python3.3/site-packages/IPython/html/tests/test_files.py", line 42, in test_hidden_files
    r.raise_for_status()

@minrk
Copy link
Member

minrk commented Mar 19, 2014

Should be finished up in #5390

ellisonbg added a commit that referenced this pull request Mar 20, 2014
@ellisonbg ellisonbg merged commit 5a09894 into ipython:master Mar 20, 2014
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants