sharepy icon indicating copy to clipboard operation
sharepy copied to clipboard

Issue Connecting to SharePoint - AttributeError: 'NoneType' object has no attribute 'text'

Open pdancel opened this issue 7 years ago • 24 comments

I am getting the following error message when trying to initiate a simple session. Any idea of what could be going wrong?

Error: `------------------------------------------------------------------------
AttributeError                         Traceback (most recent call last)
<ipython-input-43-215fda3deba1> in <module>()
      1 # (1) Authenticate
----> 2 s = sharepy.connect("https://company.sharepoint.com/")

~\AppData\Local\Continuum\anaconda3\lib\site-packages\sharepy\session.py in connect(site, username, password, auth_tld)
     18 
     19 def connect(site, username=None, password=None, auth_tld=None):
---> 20     return SharePointSession(site, username, password, auth_tld)
     21 
     22 

~\AppData\Local\Continuum\anaconda3\lib\site-packages\sharepy\session.py in __init__(self, site, username, password, auth_tld)
     59             self.password = password
     60 
---> 61             if self._spauth():
     62                 self._redigest()
     63                 self.headers.update({

~\AppData\Local\Continuum\anaconda3\lib\site-packages\sharepy\session.py in _spauth(self)
     97         # Check for errors and print error messages
     98         if token is None or root.find(".//S:Fault", ns) is not None:
---> 99             print("{}: {}".format(root.find(".//S:Text", ns).text,
    100                                   root.find(".//psf:text", ns).text).strip().strip("."))
    101             return

AttributeError: 'NoneType' object has no attribute 'text'`



Code:
`s = sharepy.connect("https://company.sharepoint.com/")`

pdancel avatar Aug 15 '18 17:08 pdancel

There's an error showing the error message.

I've just updated the develop branch with a change that should print the message properly, and tell us what's going wrong. Try that and let me know what it says.

JonathanHolvey avatar Aug 15 '18 22:08 JonathanHolvey

SyntaxError: prefix 'S' not found in prefix map

pdancel avatar Aug 15 '18 22:08 pdancel

My mistake. Can you try again now with the latest on develop?

JonathanHolvey avatar Aug 15 '18 22:08 JonathanHolvey

Still getting the same error:

Traceback (most recent call last):

  File "C:\Users\Pdancel\AppData\Local\Continuum\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 2963, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "<ipython-input-5-84bb2808ba78>", line 5, in <module>
    s = sharepy.connect("https://company.sharepoint.com",username='', password='')

  File "C:\Users\Pdancel\AppData\Local\Continuum\anaconda3\lib\site-packages\sharepy\session.py", line 20, in connect
    return SharePointSession(site, username, password, auth_tld)

  File "C:\Users\Pdancel\AppData\Local\Continuum\anaconda3\lib\site-packages\sharepy\session.py", line 59, in __init__
    if self._spauth():

  File "C:\Users\Pdancel\AppData\Local\Continuum\anaconda3\lib\site-packages\sharepy\session.py", line 100, in _spauth
    elif root.find(".//S:Detail", ns) is not None:

  File "C:\Users\Pdancel\AppData\Local\Continuum\anaconda3\lib\xml\etree\ElementPath.py", line 298, in find
    return next(iterfind(elem, path, namespaces), None)

  File "C:\Users\Pdancel\AppData\Local\Continuum\anaconda3\lib\xml\etree\ElementPath.py", line 277, in iterfind
    selector.append(ops[token[0]](next, token))

  File "C:\Users\Pdancel\AppData\Local\Continuum\anaconda3\lib\xml\etree\ElementPath.py", line 118, in prepare_descendant
    token = next()

  File "C:\Users\Pdancel\AppData\Local\Continuum\anaconda3\lib\xml\etree\ElementPath.py", line 83, in xpath_tokenizer
    raise SyntaxError("prefix %r not found in prefix map" % prefix)

  File "<string>", line unknown
SyntaxError: prefix 'S' not found in prefix map

pdancel avatar Aug 15 '18 23:08 pdancel

I can't explain this. The line number in your trace (100) doesn't match up with the line number in the source (102).

Also, the formatting of the error output is quite different between you initial post and your latest one. Are you running two different environments? Do you get the same Prefix 'S' not found in prefix map error in both?

JonathanHolvey avatar Aug 16 '18 08:08 JonathanHolvey

I am getting the same error

Traceback (most recent call last):

  File "<input>", line 2, in <module>

  File "C:\Users\dt\git clones\venv\lib\site-packages\sharepy\session.py", line 20, in connect
    return SharePointSession(site, username, password, auth_tld)

  File "C:\Users\dt\git clones\venv\lib\site-packages\sharepy\session.py", line 61, in __init__
    if self._spauth():

  File "C:\Users\dt\git clones\venv\lib\site-packages\sharepy\session.py", line 99, in _spauth
    print("{}: {}".format(root.find(".//S:Text", ns).text,

AttributeError: 'NoneType' object has no attribute 'text'

dturcanfluent avatar Aug 21 '18 20:08 dturcanfluent

@dturcanfluent can you try the develop branch instead?

JonathanHolvey avatar Aug 21 '18 21:08 JonathanHolvey

@JonathanHolvey I am running on one environment only and I do keep getting the same

"Prefix 'S' not found in prefix map" error in both.

pdancel avatar Aug 21 '18 21:08 pdancel

So now I used the develop branch and I don't get an error on sharepy.connect. However, the only message I get is "Requesting security token..." and no message after that. I tried using s.getfile and s.get, but I get error 403 for all of my requests so I'm not sure if the authentication worked.

dturcanfluent avatar Aug 22 '18 12:08 dturcanfluent

I am also facing the same issue. But the main thing is I am having the site for example "http:/testsites.sharepoint.com/deck/development". If I give that url it is throwing the error.

mkHun avatar Sep 20 '18 07:09 mkHun

I'm not able to reproduce this issue with my account. It seems that the error message that's being returned doesn't match the SOAP schema or the usual format that SharePoint uses. I've added a condition in the develop branch to print the whole of the returned XML when this happens. Be sure to remove any sensitive information from this XML (if there is any) before posting it here.

JonathanHolvey avatar Sep 20 '18 20:09 JonathanHolvey

Are you still seeing this problem?

JonathanHolvey avatar Oct 17 '18 09:10 JonathanHolvey

I am getting the same error.

File "C:\Users\KKurup1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sharepy\session.py", line 20, in connect return SharePointSession(site, username, password, auth_tld) File "C:\Users\KKurup1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sharepy\session.py", line 61, in init if self._spauth(): File "C:\Users\KKurup1\AppData\Local\Programs\Python\Python36-32\lib\site-packages\sharepy\session.py", line 99, in _spauth print("{}: {}".format(root.find(".//S:Text", ns).text, AttributeError: 'NoneType' object has no attribute 'text'

Does this have something to do with multifactor auth?

kkurup3 avatar Oct 25 '18 17:10 kkurup3

Hi Jonathan,

I also getting the same error. I use the develop branch and get a different error. Here is the output from the develop branch.

Traceback (most recent call last): File "session.py", line 180, in s = connect(site) File "session.py", line 20, in connect return SharePointSession(site, username, password, auth_tld) File "session.py", line 61, in init if self._spauth(): File "session.py", line 105, in _spauth print("Unknown error fetching security token:\n" + root.tostring()) AttributeError: 'xml.etree.ElementTree.Element' object has no attribute 'tostring'

I think @kkurup3 might be right about multifactor auth. My account is setup with 2fa.

Thanks for sharing sharepy

kevinton43 avatar Nov 27 '18 01:11 kevinton43

I am also now getting this error message. Has anyone found a solution, or at least and idea what I should look at?

Sunny-Engineer avatar Feb 09 '20 05:02 Sunny-Engineer

Had the same error fixed by adding domain to username, it should be in format [email protected]

av9ash avatar May 05 '20 02:05 av9ash

I'm also getting the error message from the original poster. Not sure what's going on?

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-19-b4b5ba758ea0> in <module>
----> 1 s = sharepy.connect("org.sharepoint.com", username='myuser', password='mypass')

~\Anaconda3\lib\site-packages\sharepy\session.py in connect(site, username, password, auth_tld)
     18 
     19 def connect(site, username=None, password=None, auth_tld=None):
---> 20     return SharePointSession(site, username, password, auth_tld)
     21 
     22 

~\Anaconda3\lib\site-packages\sharepy\session.py in __init__(self, site, username, password, auth_tld)
     59             self.password = password
     60 
---> 61             if self._spauth():
     62                 self._redigest()
     63                 self.headers.update({

~\Anaconda3\lib\site-packages\sharepy\session.py in _spauth(self)
     97         # Check for errors and print error messages
     98         if token is None or root.find(".//S:Fault", ns) is not None:
---> 99             print("{}: {}".format(root.find(".//S:Text", ns).text,
    100                                   root.find(".//psf:text", ns).text).strip().strip("."))
    101             return

AttributeError: 'NoneType' object has no attribute 'text'

emma-klein avatar Oct 22 '20 21:10 emma-klein

Hi I get the same error attempting to connect to an organisational Sharepoint site. I imagine that it uses ADFS with 2-factor authentication.

Requesting security token...Traceback (most recent call last): File "C:\ProgramData\Anaconda3\envs\mqc1\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in s = sharepy.connect("https://REDACTED.sharepoint.com") File "C:\ProgramData\Anaconda3\envs\mqc1\lib\site-packages\sharepy\session.py", line 20, in connect return SharePointSession(site, username, password, auth_tld) File "C:\ProgramData\Anaconda3\envs\mqc1\lib\site-packages\sharepy\session.py", line 61, in init if self._spauth(): File "C:\ProgramData\Anaconda3\envs\mqc1\lib\site-packages\sharepy\session.py", line 99, in _spauth print("{}: {}".format(root.find(".//S:Text", ns).text, AttributeError: 'NoneType' object has no attribute 'text'

jasonwheritage avatar Dec 03 '20 07:12 jasonwheritage

If anyone is still having this issue, please download the issue-#20 branch, which should handle the error with a generic message. It will also print the response XML, which will help with debugging if posted here.

It should look something like this:

import sharepy as sp
sp.connect('example.sharepoint.com', username='[email protected]', password='password')
<?xml version="1.0" encoding="utf-8"?><S:Envelope xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wst="http://schemas.xmlsoap.org/ws/2005/02/trust" xmlns:S="http://www.w3.org/2003/05/soap-envelope"><S:Header><psf:pp xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault"><psf:serverVersion>1</psf:serverVersion><psf:authstate>0x80048800</psf:authstate><psf:reqstatus>0x80045c01</psf:reqstatus><psf:serverInfo ServerTime="2021-01-02T03:25:05.4834669Z">ESTS-PUB-KRSLR1-LZ3-FD026-001.ProdSlices rid:0e24accf-37cd-463b-9639-e84788327101</psf:serverInfo></psf:pp></S:Header><S:Body xmlns:S="http://www.w3.org/2003/05/soap-envelope"><S:Fault><S:Code><S:Value>S:Sender</S:Value><S:Subcode><S:Value>wst:InvalidRequest</S:Value></S:Subcode></S:Code><S:Reason><S:Text xml:lang="en-US">Invalid Request</S:Text></S:Reason><S:Detail><psf:error xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault"><psf:value>0x80045C01</psf:value><psf:internalerror><psf:code>0x80045C01</psf:code><psf:text>AADSTS90023: Invalid STS request.</psf:text></psf:internalerror></psf:error></S:Detail></S:Fault></S:Body></S:Envelope>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jon/Projects/Development/Tools/sharepy/src/sharepy/session.py", line 15, in connect
    return SharePointSession(site, auth=autoauth)
  File "/home/jon/Projects/Development/Tools/sharepy/src/sharepy/session.py", line 61, in __init__
    self.auth.login(self.site)
  File "/home/jon/Projects/Development/Tools/sharepy/src/sharepy/auth/spol.py", line 25, in login
    self._get_token()
  File "/home/jon/Projects/Development/Tools/sharepy/src/sharepy/auth/spol.py", line 51, in _get_token
    raise errors.AuthError.fromxml(root)
src.sharepy.errors.AuthError: Unknown authentication error

JonathanHolvey avatar Jan 02 '21 03:01 JonathanHolvey

I was getting the same error when I tried to authenticate with my user name. Based on the comment from @av9ash I signed in with my full email and did not get the error. (On our corporate system, sometimes we sign in with a user name and sometimes with our email.)

JeffryErickson avatar Feb 23 '21 00:02 JeffryErickson

Can anyone else confirm that using your email instead of your username fixes this issue? I was under the impression that email is the only option when signing into Office365 services, including SharePoint, and hence SharePy.

JonathanHolvey avatar Feb 23 '21 00:02 JonathanHolvey

Hi Jonathan, signing up with my email (which I believe is my username) still gives the exact same issue unfortunately.

WdeZeeuw avatar Mar 31 '21 08:03 WdeZeeuw

I've started getting this error too, both in 1.3.0 and the 2.0 beta. The error reported in 2.0 is

sharepy.errors.AuthError: Unknown authentication error

It was working fine until yesterday, and then has suddenly stopped functioning. I'm using my full email as the username.

TomW28 avatar Jun 05 '21 08:06 TomW28

signing in with my email as username fixed this issue for me! On version 1.3.0

RZhangCTL avatar Oct 18 '21 17:10 RZhangCTL