Skip to content

Commit dc4e179

Browse files
authored
Merge pull request #182 from jaap3/patch-1
Fixed #179: Catch potential FileNotFoundError
2 parents bc43a32 + e1e20d7 commit dc4e179

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cachecontrol/caches/file_cache.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
FileNotFoundError
1010
except NameError:
1111
# py2.X
12-
FileNotFoundError = OSError
12+
FileNotFoundError = (IOError, OSError)
1313

1414

1515
def _secure_open_write(filename, fmode):
@@ -95,12 +95,12 @@ def _fn(self, name):
9595

9696
def get(self, key):
9797
name = self._fn(key)
98-
if not os.path.exists(name):
98+
try:
99+
with open(name, 'rb') as fh:
100+
return fh.read()
101+
except FileNotFoundError:
99102
return None
100103

101-
with open(name, 'rb') as fh:
102-
return fh.read()
103-
104104
def set(self, key, value):
105105
name = self._fn(key)
106106

0 commit comments

Comments
 (0)