sharepy
sharepy copied to clipboard
Issue Connecting to SharePoint - AttributeError: 'NoneType' object has no attribute 'text'
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/")`
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.
SyntaxError: prefix 'S' not found in prefix map
My mistake. Can you try again now with the latest on develop?
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
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?
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 can you try the develop branch instead?
@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.
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.
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.
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.
Are you still seeing this problem?
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?
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
I think @kkurup3 might be right about multifactor auth. My account is setup with 2fa.
Thanks for sharing sharepy
I am also now getting this error message. Has anyone found a solution, or at least and idea what I should look at?
Had the same error fixed by adding domain to username, it should be in format [email protected]
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'
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 "
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
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.)
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.
Hi Jonathan, signing up with my email (which I believe is my username) still gives the exact same issue unfortunately.
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.
signing in with my email as username fixed this issue for me! On version 1.3.0