2

I want to automate downloading a zipfile on another organization's sharepoint site that they have shared with my organization, inviting us as a guest using a generic company email address so we can access the files. To gain access, I provide the company email address as username and its associated AD password which authenticates access through our MS 365 organization account.

This works fine manually, but when attempting to do it through shareplum I get a credentials error.

Here is my code:

from shareplum import Site
from shareplum import Office365
from shareplum.site import Version

sharepointUsername = 'elvis.presley@suspiciousminds.org'
sharepointPassword = 'oogabooga123'
sharepointSite = 'https://abc.sharepoint.com/sites/ClientLogin/Shared Documents/Graceland/'

authcookie = Office365(website, username=sharepointUsername, 
             password=sharepointPassword).GetCookies()
site = Site(sharepointSite, version=Version.v365, authcookie=authcookie)

And here is the error:

Traceback (most recent call last):
  File "<string>", line 11, in <module>
  File "C:\arcgispro-py3-clone2\lib\site-packages\shareplum\office365.py", line 88, in get_cookies
    sectoken = self.get_security_token(self.username, self.password)
  File "C:\arcgispro-py3-clone2\lib\site-packages\shareplum\office365.py", line 80, in get_security_token
    raise Exception('Error authenticating against Office 365. Error from Office 365:', message[0].text)
Exception: ('Error authenticating against Office 365. Error from Office 365:', 'AADSTS50126: Error validating credentials due to invalid username or password.')

Any clue as why this is not working? I've checked the credentials several times using them to log in manually and it works every time (obviously the example does not have the real username/password)?

geoJshaun
  • 637
  • 2
  • 11
  • 32
  • Hi, can you share the content of `website` variable?? It should be `https://abc.sharepoint.com/` not the entire url as `sharepointSite`. Also change your `sharepointSite ` as `sharepointSite = 'https://abc.sharepoint.com/sites/ClientLogin/`. To access the folder you have to do after the login:` folder = site.Folder('Shared Documents/Graceland/')` and to get the file `folder.get_file('my_file.zip')` and `folder.check_out('my_file.zip')` – Carlo Zanocco Oct 15 '20 at 13:21

1 Answers1

1

You’re not alone, this seems to be a common issue with shareplum over the past 6 months. There’s an open issue on GitHub. The code owner is aware and is having difficulty debugging the issue.

GitHub issue: https://github.com/jasonrollins/shareplum/issues/84

I recommend working closely with the code owner to debug and resolve the issue on GitHub, or using a different library/solution altogether. Another user commented on the issue and referenced a solution that utilizes the requests library to retrieve a file that you may find useful: https://github.com/jasonrollins/shareplum/issues/84#issuecomment-627986466 .

pygeek
  • 7,356
  • 1
  • 20
  • 41