Reading an Excel object obtained with urllib2

I get the excel file using urllib2 and save in the answer below. I want to be able to process this excel file using xlrd or similar. I have included some information below, let me know if I can provide further information. How can I convert a response object to an object that I can play with?

response = <addinfourl at 199999998 whose fp = <socket._fileobject object at 0x100001010>> response.read() prints: '\xd0\xcf\x11\xe0...' Headers: Content-Type: application/vnd.ms-excel Transfer-Encoding: chunked 
+4
source share
1 answer

Using xlrd and based on its API documentation , it looks like you can use something similar to this:

 book = xlrd.open_workbook(file_contents=response.read()) 

It does not seem to support reading the file object (which, IMO, would be ideal), only accepting the file_contents method in filename or higher.

If file_contents does not exist or does not work, you will need to use tempfile to write a response to the temporary file and read this.

+5
source

All Articles