From 8eb792f9bcf4b31597da2930889f03546a7ebf25 Mon Sep 17 00:00:00 2001 From: Simon Hellbe Date: Mon, 7 Oct 2019 21:38:11 +0200 Subject: [PATCH] BUG: Patch for skipping seek() when loading Excel files from HTTPResponse object --- pandas/io/excel/_base.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pandas/io/excel/_base.py b/pandas/io/excel/_base.py index 039a0560af627..52ac6a7639491 100644 --- a/pandas/io/excel/_base.py +++ b/pandas/io/excel/_base.py @@ -1,7 +1,7 @@ import abc from collections import OrderedDict from datetime import date, datetime, timedelta -from io import BytesIO +from io import BytesIO, UnsupportedOperation import os from textwrap import fill @@ -347,7 +347,12 @@ def __init__(self, filepath_or_buffer): self.book = filepath_or_buffer elif hasattr(filepath_or_buffer, "read"): # N.B. xlrd.Book has a read attribute too - filepath_or_buffer.seek(0) + try: + filepath_or_buffer.seek(0) + except UnsupportedOperation: + # HTTPResponse does not support seek() + # GH 28825 + pass self.book = self.load_workbook(filepath_or_buffer) elif isinstance(filepath_or_buffer, str): self.book = self.load_workbook(filepath_or_buffer)