This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: os.path.ismount sometimes raises FileNotFoundError on Windows
Type: behavior Stage: patch review
Components: Windows Versions: Python 3.9, Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AkechiShiro, Dan Arad, akarei, ankeshsaha, cheryl.sabella, lazka, paul.moore, scic0, sdcards, steve.dower, tim.golden, wolma, zach.ware
Priority: normal Keywords: easy, newcomer friendly, patch

Created on 2016-12-02 14:39 by lazka, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 19109 closed akarei, 2020-03-22 13:07
Messages (11)
msg282241 - (view) Author: Christoph Reiter (lazka) * Date: 2016-12-02 14:39
It returns True for drives which don't exist and raises for paths starting with drives which don't exist.

>>> os.path.exists("C:\\")
>>> os.path.ismount("C:\\")
>>> os.path.ismount("C:\\doesnotexist")
>>> os.path.exists("F:\\")
>>> os.path.ismount("F:\\")
>>> os.path.ismount("F:\\doesnotexist")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\lazka\AppData\Local\Programs\Python\Python35\lib\", line 290, in ismount
    return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'F:\\doesnotexist'
msg357723 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2019-12-02 17:52
Traditionally we handle exceptions in* functions and return False.
msg361634 - (view) Author: Nishant Misra (scic0) Date: 2020-02-08 15:34
I would like to take this issue as my first issue to start contributing to Python development.
msg362039 - (view) Author: szb512 (sdcards) Date: 2020-02-16 00:31
I am going to think maybe it was the "os.path.ismount" command that is causing the issue. Does the file exist?
msg362238 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-02-18 23:05
> I am going to think maybe it was the "os.path.ismount" command that is causing the issue. Does the file exist?

If the file does not exist, it is definitely not a mount point. So the function should return False instead of raising an error.
msg364476 - (view) Author: Lahfa Samy (AkechiShiro) * Date: 2020-03-17 20:22
Nishant Misra are you still working on this issue, if not could I take it from now on, as my first issue and contribution to Python?
msg364486 - (view) Author: Nishant Misra (scic0) Date: 2020-03-17 22:20
Yes Lahfa Samy, you can take it up. I did not work on the issue.
msg365132 - (view) Author: Zhu Sheng Li (akarei) * Date: 2020-03-27 02:58
I submitted a PR and get reviewed by @lazka. Is there anything I should do for pushing it to next step?
msg365196 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2020-03-27 23:56
Reminding us on here is helpful (for me, anyway).

I just left a couple of suggestions to make sure we handle all the cases.

It's important when you change or add tests that you make sure the test fails without your fix - otherwise it might not be testing the fix!
msg365591 - (view) Author: Ankesh Saha (ankeshsaha) * Date: 2020-04-02 13:07
s I have tried to workout a solution for the problem. Below is my observation and possible solution.


Exception occurs for the above line if the system fails to find both drive and the path that follows it.

A 'FileNotFoundError' exception is thrown. If we can handle this exception and return false for method ismount(), then problem can be resolved.

I changed the existing code ismount method and it is working.
Existing code=>
    if _getvolumepathname:
        return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
        return False

Changed Code=>
    if _getvolumepathname:
            return path.rstrip(seps) == _getvolumepathname(path).rstrip(seps)
        except FileNotFoundError:
            return False

Please check, if this solution is correct.
msg369747 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2020-05-23 20:05
@steve.dower, please review the changes when you get a chance.  Thanks!
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73045
2020-05-23 20:05:59cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg369747
2020-04-02 13:07:34ankeshsahasetnosy: + ankeshsaha
messages: + msg365591
2020-03-27 23:56:39steve.dowersetmessages: + msg365196
2020-03-27 02:58:23akareisetmessages: + msg365132
2020-03-22 13:07:10akareisetkeywords: + patch
nosy: + akarei

pull_requests: + pull_request18470
stage: test needed -> patch review
2020-03-17 22:20:04scic0setmessages: + msg364486
2020-03-17 20:22:17AkechiShirosetnosy: + AkechiShiro
messages: + msg364476
2020-02-18 23:05:18steve.dowersetmessages: + msg362238
2020-02-16 00:31:24sdcardssetnosy: + sdcards
messages: + msg362039
2020-02-08 15:34:54scic0setnosy: + scic0
messages: + msg361634
2020-02-05 22:15:07Dan Aradsetnosy: + Dan Arad
2019-12-02 17:52:35steve.dowersetversions: + Python 3.8, Python 3.9
messages: + msg357723

keywords: + easy, newcomer friendly
type: behavior
stage: test needed
2019-03-20 21:00:58lazkasetversions: + Python 3.7, - Python 3.5
2016-12-02 22:25:52martin.pantersettitle: os.path.mount sometimes raises FileNotFoundError on Windows -> os.path.ismount sometimes raises FileNotFoundError on Windows
2016-12-02 16:13:06wolmasetnosy: + wolma
2016-12-02 14:39:20lazkacreate