Skip to content

Commit cdbe2d6

Browse files
author
Jesse Whitehouse
committed
Open output stream _after_ successful HTTP request
Changed per PR feedback Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent e609ef3 commit cdbe2d6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/databricks/sql/client.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,16 @@ def _handle_staging_get(
392392
if local_file is None:
393393
raise Error("Cannot perform GET without specifying a local_file")
394394

395-
with open(local_file, "wb") as fp:
396-
r = requests.get(url=presigned_url, headers=headers)
395+
r = requests.get(url=presigned_url, headers=headers)
397396

398-
# response.ok verifies the status code is not between 400-600.
399-
# Any 2xx or 3xx will evaluate r.ok == True
400-
if not r.ok:
401-
raise Error(
402-
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}"
403-
)
397+
# response.ok verifies the status code is not between 400-600.
398+
# Any 2xx or 3xx will evaluate r.ok == True
399+
if not r.ok:
400+
raise Error(
401+
f"Staging operation over HTTP was unsuccessful: {r.status_code}-{r.text}"
402+
)
404403

404+
with open(local_file, "wb") as fp:
405405
fp.write(r.content)
406406

407407
def _handle_staging_remove(self, presigned_url: str, headers: dict = None):

0 commit comments

Comments
 (0)