jonathanholvey / sharepy Goto Github PK
View Code? Open in Web Editor NEWSimple SharePoint authentication for Python
License: GNU General Public License v3.0
Simple SharePoint authentication for Python
License: GNU General Public License v3.0
Hi,
Thank you for this python applet, complete and light.
I've been looking for a long time how to upload a set of files to a sharepoint online document library in a recursive way..
mysite.sharepoint.com/subsites/namesite/Documents/ ..
I don't know how to write the download function of a complete directory.
Can you help me ?
I thank you in advance for you help,
I am getting a syntax error when I try to import sharepy: line 78
print("Requesting security token...\r", end="")
Extending getfile()
to return the response only (and not write to disk) would be helpful in programmatic use-cases (i.e. streaming many files to tables for an ETL process). Possibly with an additional arg or a function like getfile()
without [file.write(chunk) for chunk in response]
.
Hi,
the german office 365 has a differenct endpoint:
The extSTS.srf must be downloaded from
https://login.microsoftonline.de/extSTS.srf
instead of
https://login.microsoftonline.com/extSTS.srf
I would like to override (e.g. in connect()
) the standard url to support this use case instead of monkey patching the source.
Thanks
I'm trying to implement the auth-classes branch but getting this attribute error.
I'm unable to connect to sharepoint O365 with an email + password: the error message I receive seems not to have been reported yet:
Invalid Request: AADSTS90023: Invalid STS request
Any idea what could be causing this?
The email + password successfully work with an other python package (shareplum) which unfortunately does not offer the functionalities I need.
Solution works fine apart from when there are characters, special to XML, in the username or password.
I would advise to fix by escaping the username and password before adding them to the XML template. The method to use for this would be 'escape' from xml.sax.saxutils.
after proving username , sharepy stuck at password only enter key is working
Hi,
First off, thank you for sharing project!
The development branch fixes some issues we are having after we migrated to ADFS. Is there a release date planned?
Cheers,
Jon
Hello,
I cannot find, using this library Sharepy, which I find so far very useful, a way to read a file (meaning its content) instead of downloading it.
Is there an equivalent to "getfile" that would be something like "readfile". I have seen the following functions that are built in Sharepy session but it doesn't seem to do the trick _( _init, _spauth, redigest, save, post, getfile, buildcookie).
I can give piece of code if the description of my problem is not clear enough.
Thank you
How to import sharepy ? How to install it in python .
Hi, I have successfully used the following code to download a dataset.
"r = s.getfile("https://example.sharepoint.com/Library/Test%20File.pdf", filename="downloads/file.pdf")"
Now I'd like to work with the dataset directly in the same work session without importing the dataset from local drive. For example, as a Pandas dataframe. Any advice on this?
Hi,
I am new in Python scripting, I am looking to download files directly to Sharepoint channel using Python instead of downloading it into the download folder. I don't want python to use my local drive to download files.
Can anybody help me in here?
The load and save methods do not close the session.pkl file. In both cases the file is opened without a with block.
@alex00321 said:
Hi I'm new to this case, but I'm trying to use sharePy to post file. The problem I got here is I don't have the main site like company.sharepoint.com. I only could access the sub site like company.sharepoint.com/sites/mine. So is there any way you could help? Thanks!
Copied from #42 (comment)
Hi Jonathan,
I was able to download file using get method but not getting any success in uploading file to sharepoint location. Can you please suggest how to use post method to upload the file
Hey I wanted to ask if there is a way to send delete API Calls via the sharepy Library as there is no requests equivalent of delete() in your source code.
Grateful for any helping hand.
Effectively trying to load an .xlsx file on Sharepoint into a pandas dataframe but I can't seem to be able to get the json() out properly. Are there any additional headers I need to be passing in? Or how would you suggest to decode this properly?
Thanks.
>>> import sharepy
>>> s = sharepy.connect('mysite.sharepoint.com', username=username, password=password)
Requesting security token...
Requesting access cookie...
Authentication successful
>>> response = s.get('https://mysite.sharepoint.com/sites/SiteDir/_layouts/15/Doc.aspx?OR=teams&action=edit&sourcedoc={99E8E198-999C-99E9-93D3-9972990AE2D6}')
>>> response.headers
{'Cache-Control': 'no-cache, no-store', 'Pragma': 'no-cache', 'Content-Length': '23637', 'Content-Type': 'text/html; charset=utf-8', 'Content-Encoding': 'gzip', 'Expires': '-1', 'Vary': 'Accept-Encoding', ......
>>> response.json()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/requests/models.py", line 892, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/python/3.6.4_3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 2)
this is needed.
Hi Jonathan,
I am using your library to try and connect to my organization's sharepoint and download files. However, when I try to access the file I need I get : "Authentication Failure: Direct login to WLID is not allowed for this federated namespace". Have you seen this before / can your library handle this issue? I recognize that there is also a possibility that this is a configuration issue on my organization's side.
Thanks,
Emma
I am trying to access our company's sharepoint account but there is a multi-factor authentication required to login. Basically we receive a text message containing a one-time password every time we try to login into sharepoint. Due to this, I can connect to sharepoint using python. What are the possible solutions for this?
I'm unable to connect to Sharepoint, the process fails when requesting a security token. My company uses multi-factor authentication through the Microsoft Authenticator app, and I wonder if that could be the problem. Is there any way around this or is something else causing the error?
s = sharepy.connect('https://company.sharepoint.com/')
Enter your username: [email protected]
Enter your password: ········
Requesting security token...
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/var/folders/cf/x7x_4qzj751c392s5rsm74d00000gp/T/ipykernel_90800/209908182.py in <module>
----> 1 s = sharepy.connect('https://company.sharepoint.com/')
/Applications/anaconda3/lib/python3.9/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
/Applications/anaconda3/lib/python3.9/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({
/Applications/anaconda3/lib/python3.9/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'
I am getting an error of Digest request failed printed and an exception at line 150 of session.py (kwargs["headers"]["Authorization"] = "Bearer " + self._redigest()
) after a few thousand (~7,000 to 14,000) create and post requests. The number of requests before the error occurs vary. I believe the digest request is returning None
. Code has been running OK for a few months until yesterday. I am wondering if anyone else is running into the same issue or has found a workaround.
I am sure my credentials are correct. Still I get Authentication Failure error.
import sharepy
s = sharepy.connect(<url_here>, "username", "password")
Hello:
Noticed that the authentication relies on microsoft online.
Any suggestion about on-premises authentication?
Line 79 in ffe4f68
We're evaluating sharepy as an alternative to https://github.com/requests/requests-ntlm
I don't think this feature currently exists in this package. Can anyone confirm?
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/")`
Hello,
I'm getting "Authentication Failure: AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password" when I try to connect with s.connect(). I know the creds are valid since I use them all the time, and I have validate the URL.
I am trying to connect to a sharepoint server using the sharepy.connect function. For the same credentials it lets me connect the server through a web browser.
But when i try connecting through my python code it throws the following error :-
Invalid Request: The partner DNS used in the login request cannot be found
Any idea why this is happening
I am a python noob. I had no troubles accessing Sharepoint Rest API for an HTTP version of SharePoint through the standard requests module. But once I move over to the HTTPS version of my SharePoint server no matter what I seem to do, it won't work. So I am attempting to use this lovely module...
I either get this error when using username "[email protected]"
File "C:\Python36\lib\site-packages\sharepy\session.py", line 97, in _spauth
print("{}: {}".format(root.find(".//S:Text", ns).text,
AttributeError: 'NoneType' object has no attribute 'text'
or when using "mpowell" or "winntdom\mpowell"
Authentication Failure: AADSTS90019: No tenant-identifying information found in either the request or implied by any provided credentials
Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED]
I know its something I'm not understanding but I hope that you guys can help.
Some things to know, it is a SharePoint on in intranet location at my work, we don't have standard Office365 accounts, our 365 accounts contain our company address so mine is [email protected]. Unfortunately I cannot share my SharePoint site. I am currently using Python 3.6
Hey Jonathan,
thanks for the quick replies so far.
As suggested in the last Issue (#47) I freshly downloaded the beta v2.0.0 Branch and tried running a small test script which creates a new Folder (POST), gets some information of it (GET) and finally deletes the folder (DELETE).
from Local import sharepy as sharepy
s = sharepy.connect(server_url, username=user, password=passwd)
uri = "https://example.sharepoint.com/sites/Test-Site/_api/web/folders/add('/sites/Test-Site/Freigegebene Dokumente/test')"
r = s.post(uri)
uri = "https://example.sharepoint.com/sites/Test-Site/_api/web/GetFolderByServerRelativeUrl('/sites/Test-Site/Freigegebene Dokumente/test')"
r = s.get(uri)
r = s.delete(uri)
The new version changed which errors I get as a response from the API:
POST Error Message:
{
"error": {
"code": "-2130575251, System.Runtime.InteropServices.COMException",
"message": {
"lang": "de-DE",
"value": "Die Sicherheits\u00fcberpr\u00fcfung f\u00fcr diese Seite ist ung\u00fcltig. Klicken Sie auf die Schaltfl\u00e4che 'Zur\u00fcck' Ihres Browsers, aktualisieren Sie dann die Seite, und starten Sie den Vorgang erneut."
}
}
}
value -> The Security check for this site is invalid... and so on
GET Error Message -> just the usual IOException because of the missing folder (works if I manually create the folder)
DELETE Error Message (after manually creating the folder):
{
"error": {
"code": "-2130575251, System.Runtime.InteropServices.COMException",
"message": {
"lang": "de-DE",
"value": "Die Sicherheits\u00fcberpr\u00fcfung f\u00fcr diese Seite ist ung\u00fcltig. Klicken Sie auf die Schaltfl\u00e4che 'Zur\u00fcck' Ihres Browsers, aktualisieren Sie dann die Seite, und starten Sie den Vorgang erneut."
}
}
}
value -> The Security check for this site is invalid... and so on
The Authentication type is SharepointOnline from what I understood.
I've been using this module successfully for about a week and have been able to connect, download, and upload files.
I recently added an option to my script to delete the old sp-session.pkl so when the script is run again the user must enter their credentials again instead of automatically loading the sp-session.pkl.
Now when I attempt to authenticate a new session I receive the message:
Authentication Failure: AADSTS70002: Error validating credentials. AADSTS50126: Invalid username or password"
If I load a copy of the old sp-session.pkl it authenticates and works fine.
Attempting to login with another user also fails, but logging in to sharepoint online in a web browser works fine.
Any idea what could be causing this?
→ pip install sharepy
Collecting sharepy
Downloading https://files.pythonhosted.org/packages/74/29/1acfb5c02cb0dbd117a73e8f38c5c5840813923a009c27c1c1705e6d9f03/sharepy-1.3.0.tar.gz
Building wheels for collected packages: sharepy
Running setup.py bdist_wheel for sharepy ... done
Stored in directory: /Users/person/Library/Caches/pip/wheels/7e/eb/cf/63bc25516388731f73ef0114f9bb24b32ca7e0f8dbeeb7baf7
Successfully built sharepy
Installing collected packages: sharepy
Successfully installed sharepy-1.3.0
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
in ~/Projects/proof/poc/sharepoint/sharepy on git:master ● [13:20:55]
→ python
Python 2.7.12 (default, Jun 29 2016, 14:05:02)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sharepy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/sharepy/__init__.py", line 1, in <module>
from .session import SharePointSession
File "/usr/local/lib/python2.7/site-packages/sharepy/session.py", line 81
print("Requesting security token...\r", end="")
This seems like Python 3.0 syntax so it likely won't work as-is on 2.7?
Hi Jonathan,
Thank you for the python module.
I recently starting getting this error when using Sharepy when i have switched VPN. I think previous version of shrepy was updated at my local end by one of my friend contacting you. The updated one used a SAML xml template to structure request. THe New VPN uses SAM 2.0. Do you have any idea about this ?
Is it possible to authenticate through Sharepy using Client ID and secret(of sharepoint teams site) as can be done in Office365-REST-Python-Client. This would be huge as I don't want to have my username and password credentials in code that needs to be used by several others and having the input prompt is not viable in an automated environment
A release of SharePy v2 has been in the works for quite a while, but has been held up due to a lack of testing. This release introduces support for federated authentication, with the SharePointADFS
auth class, however, I don't have access to an ADFS-enabled site to test it throughly.
If you want to help out with testing, please install it using pip:
pip install --pre sharepy
If you find a bug, please create an issue with v2
in the title. Be sure to include as much detail as possible in your bug report, including:
sharepy.auth.detect('[email protected]')
if you're not sure)A major refactor of SharePy to provide a standard Requests auth interface.
sharepy.connect()
auth_tld
argument from sharepy.connect()
and replaced with an login_url
property in auth classessetup.py
script to repositoryIs it possible sharepy will add support for batch requests in the future?
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/make-batch-requests-with-the-rest-apis
I'm getting Authentication Failure: AADSTS53003: Access has been blocked by Conditional Access policies. The access policy does not allow token issuance.
How can I fix it?
Hi, I'm a bit of a novice, but the documentation code from the read me (Requests authentication) triggers an error "module 'sharepy' has no attribute 'auth'".
print(dir(sharepy)) which printed ['SharePointSession', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'path', 'spec', 'connect', 'load', 'session']. I was expecting to see auth listed. Where am I going wrong?
I read the release notes from Jan 2021, is it possible the read me documentation hasn't been updated?
This package appears to be exactly what i'm looking for, I'm just having trouble getting it up and running. Thanks for any response in advance!
Hi,
I am trying to initiate a chuck upload for large files. The sharepoint REST API offers this but i am failing to implement it via Python. I think it would be beneficial to add another function which reads the input file in chunks sends it accordingly. Do you think this is in your pipeline for this project?
Thanks :)
Traceback (most recent call last):
File "xxx\lambda_function.py", line 66, in <module>
uploadToSharepoint(SPUrl, username, password, siteName, libraryName, path)
File "xxx\lambda_function.py", line 14, in uploadToSharepoint
s = sharepy.load()
File "xxx\sharepy\session.py", line 27, in load
if session._redigest() or session._spauth():
File "xxx\sharepy\session.py", line 124, in _redigest
response = requests.post("https://" + self.site + "/_api/contextinfo", data="", headers={"Cookie": self.cookie})
AttributeError: 'SharePointSession' object has no attribute 'cookie'
I am getting this error while executing.
I get this error when running this code:
File "/usr/local/lib/python3.6/site-packages/requests/sessions.py", line 166, in resolve_redirects
raise TooManyRedirects('Exceeded {} redirects.'.format(self.max_redirects), response=resp)
requests.exceptions.TooManyRedirects: Exceeded 30 redirects.
Can max_redirects be added to the code?
i gave correct credentials and url but dont know its giving this error below is the code that im using
import sharepy
from sharepy import connect
from sharepy import SharePointSession
server="https://company.sharepoint.com"
user="[email protected]" // username
password="passcode" //passcode
s = sharepy.connect(server,user,password)
Hi,
is there a way to use a guest authentication for sharepoints?
I would like to write a script, running on a server, but I don't feel like putting my password on the server.
Therefor I added a guest account to the sharepoint, which is able to read the sharepoint on the website. However I can't login using the authentication system from sharepy.
Any suggestions for doing this?
Best regards,
Hi am trying use this code to connect to my office sharepoint link but it keeps giving username password error. Am pretty sure there is no issue with the credentials. Is it something with authentication mechanism
I'm unable to connect and get this error. I've tried using my credentials directly through the web URL and they are correct.
I can't see any other issues referring to this error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.