shareplum icon indicating copy to clipboard operation
shareplum copied to clipboard

Error authenticating against Office 365. Error from Office 365:

Open odairvaz opened this issue 4 years ago • 35 comments

Hello everyone, I'm trying to upload some files to SharePoint in Office 365 but the authentication fails even though that I put the right credentials.Here's the code:

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

#get all the csv files
csv_files = list(filter(lambda x: '.csv' in x, os.listdir('./csvfiles')))

# Office 365 Authentication
authcookie = Office365('https://tenant.sharepoint.com',
                       username='[email protected]', password='password').GetCookies()
site = Site('https://tenant.sharepoint.com/sites/Folder',
            version=Version.v365, authcookie=authcookie)

However, I do manage to log in and upload data with my personal account, but I can’t upload data with my organizational account Here’s the message error when I try to log with my organizational account:

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.')

Is there any way to fix it?

Thanks in advance

odairvaz avatar Apr 15 '20 13:04 odairvaz

Do you have any strange characters in your user name or password? The Office365 authentication user xml.sax.saxutils.escape() to clean up special characters, but maybe it is interfering?

jasonrollins avatar Apr 16 '20 00:04 jasonrollins

Do you have any special characters in your username and password?

On Wed, Apr 15, 2020 at 8:43 AM Odair Vaz [email protected] wrote:

Hello everyone, I'm trying to upload some files to SharePoint in Office 365 but the authentication fails even though that I put the right credentials.Here's the code.

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

#get all the csv files csv_files = list(filter(lambda x: '.csv' in x, os.listdir('./csvfiles'))) Office 365 Authentication

authcookie = Office365('https://tenant.sharepoint.com', username='[email protected]', password='password').GetCookies() site = Site('https://tenant.sharepoint.com/sites/Folder', version=Version.v365, authcookie=authcookie) ` However, I do manage to log in and upload data with my personal account, but I can’t upload data with my organizational account Here’s the message error when I try to log with my organizational account:

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.')

Is there any way to fix it?

Thanks in advance

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jasonrollins/shareplum/issues/84, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVTVRFFTXIOEX6N4MJ3R3RMW2YDANCNFSM4MISYCVQ .

jasonrollins avatar Apr 16 '20 23:04 jasonrollins

I'm having the same issue, and no special characters are observed in my username and password. Can you please help?

vennamanand1 avatar Apr 27 '20 19:04 vennamanand1

Can you try version 0.4.5 and see if that one works?

jasonrollins avatar Apr 27 '20 22:04 jasonrollins

Tried with 0.4.5 and the error is still the same.

vennamanand1 avatar Apr 28 '20 06:04 vennamanand1

please help

vennamanand1 avatar Apr 28 '20 06:04 vennamanand1

Try setting verify_ssl=False in your site object. Site(verify_ssl=False)

On Tue, Apr 28, 2020, 1:00 AM vennamanand1 [email protected] wrote:

please help

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jasonrollins/shareplum/issues/84#issuecomment-620398391, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVTVT7TB4U33PTW6XQASDROZWJNANCNFSM4MISYCVQ .

jasonrollins avatar Apr 28 '20 13:04 jasonrollins

Do you have any strange characters in your user name or password? The Office365 authentication user xml.sax.saxutils.escape() to clean up special characters, but maybe it is interfering?

no, my password and username doesn't have stange characters

odairvaz avatar Apr 28 '20 15:04 odairvaz

I changed my code but i'm still having the same issue

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

#get all the csv files
csv_files = list(filter(lambda x: '.csv' in x, os.listdir('./csvfiles')))

# Office 365 Authentication
authcookie = Office365('https://tenant.sharepoint.com',
                       username='[email protected]', password='password').GetCookies()
site = Site('https://tenant.sharepoint.com/sites/Folder',
            version=Version.v365, authcookie=authcookie, verify_ssl=False)

But i keep having the same error

Traceback (most recent call last):
  File "rest-api.py", line 19, in <module>
    authcookie = Office365('https://tenant.sharepoint.com',
  File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\site-packages\shareplum\office365.py", line 87, in get_cookies
    sectoken = self.get_security_token(self.username, self.password)
  File "C:\Users\username\AppData\Local\Programs\Python\Python38-32\lib\site-packages\shareplum\office365.py", line 79, 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.')

odairvaz avatar Apr 28 '20 16:04 odairvaz

I'm having a similar issue (tried 0.5.0 and 0.4.5)

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

authcookie = Office365('https://abc.sharepoint.com', username=username, password=password).GetCookies()
site = Site('https://abc.sharepoint.com/sites/MySharePointSite/', version=Version.v365, authcookie=authcookie, verify_ssl=False)

with this error:

Exception: ('Error authenticating against Office 365. Was not able to find an error code. Here is the SOAP response from Office 365'

It appears it can't get a security token.

kmahanna avatar Apr 28 '20 20:04 kmahanna

I am also facing a similar issue.

The code I used.

from shareplum import Site
from shareplum import Office365
from shareplum.site import Version
authcookie = Office365('https://***.sharepoint.com/', username='***', password='***').GetCookies()
site = Site('https://***.sharepoint.com/sites/Folder/', version=Version.v2016, authcookie=authcookie)
folder = site.Folder('Shared Documents/ME/')
folder.get_file('xyz.xlsx')

And the error I am facing is.

File "***\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:', "AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access ''.")

amanmajeed avatar May 09 '20 09:05 amanmajeed

@jasonrollins can you help us with this issue, do you have any other suggestion ? thanks

odairvaz avatar May 13 '20 09:05 odairvaz

I was able to use this work around to pull data from the file I needed with requests_ntlm. My goal was to download the original file, but this will have to do. Accessing SharePoint 2013...

from requests_ntlm import HttpNtlmAuth
import requests
from io import BytesIO

auth = HttpNtlmAuth(username = username,
                     password = password)
 
responseObject = requests.get(url, auth = auth)

file = BytesIO(responseObject.content)
df = pd.read_excel(file)

kmahanna avatar May 13 '20 13:05 kmahanna

I also had this error

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.')

@jasonrollins It would be great if you can help us here.

Pear1125 avatar Jul 14 '20 02:07 Pear1125

Hi all,

Facing this error too - 'Error authenticating against Office 365. Error from Office 365:', 'AADSTS50126: Error validating credentials due to invalid username or password.'

Credentials works just fine if I try to login directly into SP or if I use my company email. But using the service account email, I can't pass that error.

Any help would be appreciated.

nmduarte avatar Oct 02 '20 19:10 nmduarte

Apologies. I'm not really sure how to debug logins. Some people have issues with their sites and some don't. I only have access to a personal Office 365 sharepoint site so I'm limited by what I can test.

On Fri, Oct 2, 2020 at 2:55 PM Nuno Tavares [email protected] wrote:

Hi all,

Facing this error too - 'Error authenticating against Office 365. Error from Office 365:', 'AADSTS50126: Error validating credentials due to invalid username or password.'

Credentials works just fine if I try to login directly into SP or if I use my company email. But using the service account email, I can't pass that error.

Any help would be appreciated.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jasonrollins/shareplum/issues/84#issuecomment-702929449, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOVTVUTRB7RVNUDOHHREPLSIYV4RANCNFSM4MISYCVQ .

jasonrollins avatar Oct 08 '20 02:10 jasonrollins

@jasonrollins The issues seems to be because of multi-factor authentication(such as okta) implemented on Office 365. I believe you are not facing this issue since your Office 365 has single-point authentication.

divy-works avatar Dec 21 '20 21:12 divy-works

So I guess the question is how do we account for multi-factor authentication?

BrandonMFong avatar Feb 02 '21 16:02 BrandonMFong

So I guess the question is how do we account for multi-factor authentication?

I vote for closing this issue. Multi-factor authentication has been created to prevent automated login. If someone wants to automate data storage in SharePoint then they should ask IT Team to create exception for the login account. Trying to solve multi-factor authentication could be out of scope of your work.

divy-works avatar Feb 02 '21 17:02 divy-works

Exception: ('Error authenticating against Office 365. Error from Office 365:', 'AADSTS50034: The user account {EmailHidden} does not exist in the gmail.com directory. To sign into this application, the account must be added to the directory.')

Same problem and I confirm there isn't multi-factor authentification

black-syphilis avatar Nov 09 '21 22:11 black-syphilis

Exception: ('Error authenticating against Office 365. Error from Office 365:', 'AADSTS50034: The user account {EmailHidden} does not exist in the gmail.com directory. To sign into this application, the account must be added to the directory.')

Same problem and I confirm there isn't multi-factor authentification

Same issue to me.

ghost avatar Nov 25 '21 06:11 ghost

Hello, guys, anyone can solve this issue? I also facing this issue:

raise Exception('Error authenticating against Office 365. Error from Office 365:', message[0].text) Exception: ('Error authenticating against Office 365. Error from Office 365:', 'AADSTS90023: Invalid STS request.')

Colin-Root avatar Apr 21 '22 05:04 Colin-Root

So is there just no way to use SharePlum on a SharePoint site that requires MFA? Is there no way to call the prompt to ask the user to login using MFA?

CodePidgy avatar May 16 '22 13:05 CodePidgy

This is my code. Who can solve this problem

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

Office 365 Authentication

authcookie = Office365('https://xxxx.sharepoint.com/', username='[email protected]', password='xxxxxxxx').GetCookies()

print(authcookie) site = Site('https://xxxxx.sharepoint.com/sites/site2', version=Version.v365, authcookie=authcookie, verify_ssl=False)

dir = 'Shared Documents\test' f = site.Folder(dir)

for file in f.files: print('--------') print(file) d = f.get_file(file['Name']) print(d)

for folder in f.folders: print(folder)

xingfengf21 avatar Jun 22 '22 07:06 xingfengf21

I am getting the same error, anyone has any solution?

bikashh1207 avatar Jul 07 '22 10:07 bikashh1207

Even I'm facing Exception: ('Error authenticating against Office 365. Was not able to find an error code. Here is the SOAP response from Office 365.

is there any solution?

manoharkakumani avatar Sep 27 '22 10:09 manoharkakumani

same error for me too... but not progressive way on that...

ranjith590 avatar Oct 11 '22 06:10 ranjith590

I am getting the same error pls hep me on this. Thanks

shivshankarpandit avatar Oct 19 '22 06:10 shivshankarpandit

Stuck with the same issue and looking for a solution.. Thanks..

ramvoci avatar Oct 24 '22 17:10 ramvoci

same issue here as well. IT said they will not remove MFA either. Has anyone found a different library?

elohbeck87 avatar Oct 27 '22 16:10 elohbeck87