Python xlrd(Python Excel)和Amazon S3的IOError
我正在做一个简单的Python(Django)应用程序,它读取一个Excel文件并在屏幕上打印它的一部分。 当我用本地PC上存储的excel文件在本地运行时,效果很好。
代码如下:
from xlrd import open_workbook def hello(request): wb = open_workbook('test.xlsx') sh = wb.sheet_by_index(0) a = sh.cell_value(rowx=0, colx=0) return HttpResponse(a)
不过,当我尝试从S3读取文件使用这个:
wb = open_workbook('http://s3.amazonaws.com/mybucketsample/test.xlsx')
我收到以下错误:
IOError at / [Errno 22] invalid mode ('r') or filename: 'http://s3.amazonaws.com/mybucketsample/test.xlsx'
我究竟做错了什么?
非常感谢,
埃德
也许这工作:
import urllib2 url = 'http://s3.amazonaws.com/mybucketsample/test.xlsx' filecontent = urllib2.urlopen(url).read() wb = open_workbook(file_contents=filecontent)