0

I have been trying to download a .csv file from sharepoint via python, but failed. I am doing the following which I found in an answer in stackoverflow.

# Access sharepoint
csv = requests.get(url="https://foobar/testbook.xlsx", data={}, auth=(email, pass))
my_df = pandas.read_csv(StringIO(csv.text))
print(my_df)

The above prints:

Empty DataFrame
Columns: [403 FORBIDDEN]
Index: []

There's no error in the output so I guess my authentication fails? I am searching for a way to download/upload files from/to sharepoint, with authentication.

Any help is appreciated.

Thanks

Lev
  • 673
  • 1
  • 12
  • 29

3 Answers3

1

SharePoint usually uses NTLM authentication while the "auth" parameter in requests is short for basic authentication.

Try using ntlm authentication as explained here: How to use Python requests to perform NTLM SSPI authentication?

Ayval Ron
  • 21
  • 3
0

First register your application using this methodology

Once you have collected client id and secret.

Then use this method to download file via Office365-REST-Python-Client

after authenticating

client_credentials = ClientCredential('{client_id}','{client_secret}')
ctx = ClientContext('{url}').with_credentials(client_credentials)
Karan Bhandari
  • 370
  • 3
  • 12
-1

Try to use this python package and its class called SharePoint.

You can find it on Github using the following link:

https://github.com/Tax-Justice-Network/tjn_tools

dcs
  • 9
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 01 '21 at 15:02