快一点.
我有一个位于sharepoint驱动器上的XLSX文件,无法在python中使用openpyxl打开它,如果它存储在我的本地驱动器上,它可以正常工作.
我试过这个.
from openpyxl import load_workbook wb = load_workbook('https://content.potatocompany.com/workspaces/PotatoTeam/Shared Documents/XYZ errors/XYZ Errors_Confirm.xlsx')
抛出此异常:
C:\Anaconda\lib\site-packages\openpyxl\reader\excel.py in load_workbook(filename, use_iterators, keep_vba, guess_types, data_only) 123 except (BadZipfile, RuntimeError, IOError, ValueError): 124 e = exc_info()[1] --> 125 raise InvalidFileException(unicode(e)) 126 wb = Workbook(guess_types=guess_types, data_only=data_only) 127 InvalidFileException: [Errno 22] invalid mode ('rb') or filename: 'https://...
我错过了什么吗?我需要阅读python中其中一个工作表的内容.
编辑:
使用crussell的建议,我收到401 UNAUTHORIZED :
import requests import urllib from openpyxl import load_workbook from requests.auth import HTTPBasicAuth file = "https://content.potatocompany.com/workspaces/PotatoTeam/Shared Documents/XYZ errors/XYZ Errors_Confirm.xlsx" username = 'PotatoUser' password = 'PotatoPassword' resp=requests.get(file, auth=HTTPBasicAuth(username, password)) print(resp.content)
似乎sharepoint和请求不兼容,包括摘要式身份验证和基本身份验证 http://docs.python-requests.org/en/latest/user/authentication/