Read xlsx stored in sharepoint location using openpyxl in python?

quick.

I have an XLSX file located on a sharepoint disk and cannot open it with openpyxl in python, it works well if it is stored on my local disk.

I have tried this.

from openpyxl import load_workbook
wb = load_workbook('https://content.potatocompany.com/workspaces/PotatoTeam/Shared Documents/XYZ errors/XYZ Errors_Confirm.xlsx')

Throws this exception:

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://...

Am I missing something? I need to read the contents of one of the sheets in python.


EDIT:

Using crussell's advice, I get 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)

It seems that sharepoint and requests are incompatible with both Digest authentication and basic authentication http://docs.python-requests.org/en/latest/user/authentication/

+4
source share
3

, -, urllib.

import urllib
file = "https://content.potatocompany.com/workspaces/PotatoTeam/Shared Documents/XYZ errors/XYZ Errors_Confirm.xlsx"
urllib.urlretrieve(file,"test.xlsx")

, urllib, -, requests. :

import requests
file = "https://content.potatocompany.com/workspaces/PotatoTeam/Shared Documents/XYZ errors/XYZ Errors_Confirm.xlsx"

username = 'myUsername'
password = 'myPassword'

r=requests.get(file, auth=HTTPBasicAuth(myUsername, myPassword))
output = open('test.xlsx', 'wb')
output .write(resp.content)
output.close()

:

pip install requests
+1

, , . :

import urllib2
from openpyxl import load_workbook
import StringIO

data = urllib2.urlopen("https://content.potatocompany.com/workspaces/PotatoTeam/Shared Documents/XYZ errors/XYZ Errors_Confirm.xlsx")
xlsx = data.read()
wb = load_workbook(StringIO.StringIO(xlsx))

Python StringIO , .

0

SP , , "https:" , load_workbook().

from openpyxl import load_workbook
file = '//content.potatocompany.com/workspaces/PotatoTeam/Shared Documents/XYZ errors/XYZ Errors_Confirm.xlsx'
wb = load_workbook(file)

, SP. NTML, , HttpNtlmAuth request_ntml.

, , - , request_ntml

0
source

Source: https://habr.com/ru/post/1619365/


All Articles