Coder Social home page Coder Social logo

python-sharepoint-office365-api's Introduction

Python SharePoint Office365 API

You will find example on connecting to Office 365 SharePoint using the Office 365 Rest Python Client package.

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

sharepoint_email

sharepoint_password

sharepoint_url_site

sharepoint_site_name

sharepoint_doc_library

Installation

Create Virtual Environment

  python -m venv env

Activate Environment

  source env/Scripts/activate

Install Packages

  pip install -r requirements.txt

Install Office365 API Package Directly from Github

  pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git#egg=Office365-REST-Python-Client

python-sharepoint-office365-api's People

Contributors

iamlu-coding avatar luisflores189544 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

python-sharepoint-office365-api's Issues

Could not upload file to sharepoint

Hi @iamlu-coding

As tested this code, I could download file from sharepoint, and could not upload file to sharepoint via script, but I can upload via GUI (same path)

The error returned 403 code:

File "/home/azureuser/.local/lib/python3.8/site-packages/office365/runtime/client_object.py", line 44, in execute_query
self.context.execute_query()
File "/home/azureuser/.local/lib/python3.8/site-packages/office365/runtime/client_runtime_context.py", line 162, in execute_query
self.pending_request().execute_query(qry)
File "/home/azureuser/.local/lib/python3.8/site-packages/office365/runtime/client_request.py", line 62, in execute_query
raise ClientRequestException(*e.args, response=e.response)
office365.runtime.client_request_exception.ClientRequestException: ('-2147024891, System.UnauthorizedAccessException', 'Access denied.', "403 Client Error: Forbidden for url

Is there any advice on this error?

Authentication failed "saml_token_provider"

Using the download_files.py from the repo, appear to have an authentication failure. I am using this on my work account. I have not been able to find any documentation on the office 365 api to help debug the issue. Appears to be an error with "saml provider". If you have any suggestions please do advise. Thank you.

Observed behavior
the download script appears to fail at the authentication stage.

Expected behavior
the download script completes the authentication and downloads specified file

Error log
Traceback (most recent call last): File "\python-sharepoint-office365-api\examples\download_files.py", line 41, in <module> get_files_by_pattern(FILE_NAME_PATTERN, FOLDER_NAME) File "\python-sharepoint-office365-api\examples\download_files.py", line 32, in get_files_by_pattern files_list = SharePoint()._get_files_list(folder) File "\python-sharepoint-office365-api\examples\office365_api.py", line 31, in _get_files_list root_folder.expand(["Files", "Folders"]).get().execute_query() File "\Environments\env_office\lib\site-packages\office365\runtime\client_object.py", line 44, in execute_query self.context.execute_query() File "\Environments\env_office\lib\site-packages\office365\runtime\client_runtime_context.py", line 181, in execute_query self.pending_request().execute_query(qry) File "\Environments\env_office\lib\site-packages\office365\runtime\client_request.py", line 57, in execute_query response = self.execute_request_direct(request) File "\Environments\env_office\lib\site-packages\office365\runtime\client_request.py", line 69, in execute_request_direct self.beforeExecute.notify(request) File "\Environments\env_office\lib\site-packages\office365\runtime\types\event_handler.py", line 21, in notify listener(*args, **kwargs) File "\Environments\env_office\lib\site-packages\office365\sharepoint\client_context.py", line 212, in _authenticate_request self.authentication_context.authenticate_request(request) File "\Environments\env_office\lib\site-packages\office365\runtime\auth\authentication_context.py", line 97, in authenticate_request self._provider.authenticate_request(request) File "\Environments\env_office\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py", line 77, in authenticate_request self.ensure_authentication_cookie() File "\Environments\env_office\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py", line 84, in ensure_authentication_cookie self._cached_auth_cookies = self.get_authentication_cookie() File "\Environments\env_office\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py", line 97, in get_authentication_cookie token = self._acquire_service_token_from_adfs(user_realm.STSAuthUrl) File "\Environments\env_office\lib\site-packages\office365\runtime\auth\providers\saml_token_provider.py", line 140, in _acquire_service_token_from_adfs assertion_node = dom.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", 'Assertion')[0].toxml() IndexError: list index out of range

Authentication not working

Hello,

When trying to authenticate I get error:
Cannot get binary security token for from https://login.microsoftonline.com/extSTS.srf

Any solutions for this error?

Uploading file in chunks gives me an exception when showing progress status

Command : (env) PS C:\Users\INSG03615\Downloads\Python-SharePoint> python upload_files_in_chunks.py "C:\Users\INSG03615\Downloads\Python-SharePoint\storage\Upload_Chunks" General/Testing/Test 17531 None

Traceback (most recent call last):
File "C:\Users\INSG03615\Downloads\Python-SharePoint\upload_files_in_chunks.py", line 38, in
upload_files(ROOT_DIR, SHAREPOINT_FOLDER_NAME, int(CHUNK_SIZE), FILE_NAME_PATTERN)
File "C:\Users\INSG03615\Downloads\Python-SharePoint\upload_files_in_chunks.py", line 22, in upload_files
SharePoint().upload_file_in_chunks(file[1], sharepoint_folder, chunk_size, progress_status, **data)
File "C:\Users\INSG03615\Downloads\Python-SharePoint\office365_api.py", line 72, in upload_file_in_chunks
response = target_folder.files.create_upload_session(
TypeError: FileCollection.create_upload_session() got an unexpected keyword argument 'file_size'

upload_files_in_chunks.py example gives me an exeption

I get an error executing the upload_files_in_chunks.py example:

(venv) PS C:\dev\tmp\sharepoint> python.exe .\upload_files_in_chunks.py . tmp 1000 backup_webservices_20230227-020001.tar.gz
Traceback (most recent call last):
File "C:\dev\tmp\sharepoint\upload_files_in_chunks.py", line 38, in
upload_files(ROOT_DIR, SHAREPOINT_FOLDER_NAME, int(CHUNK_SIZE), FILE_NAME_PATTERN)
File "C:\dev\tmp\sharepoint\upload_files_in_chunks.py", line 22, in upload_files
SharePoint().upload_file_in_chunks(file[1], sharepoint_folder, chunk_size, progress_status, **data)
File "C:\dev\tmp\sharepoint\office365_api.py", line 72, in upload_file_in_chunks
response = target_folder.files.create_upload_session(
TypeError: create_upload_session() missing 1 required positional argument: 'path_or_file'

download_files_with_subfolder.py downloading Documents to root folder

Hi,

When I use download_files_with_subfolder.py to download the folder structure and files from SharePoint I am finding that it downloads the files in "Shared Documents" to the folder I specify, but all other folders are created in the root of the drive.

I have tested on both Windows 10 and on a Linux machine (running PiOS).

Stepping through the code it looks like PurePath is mangling the file path so when it tries to create the folders it puts them in the root. In the case of windows, c: and on Linux .

Any idea's?

Thanks

Error in download_latest_file function

Hi, in the function download_latest_file in row dt_obj = datetime.datetime.strptime(file.time_last_modified, date_format) was showing error, but i resolved with dt_obj = datetime.datetime.strftime(file.time_last_modified,date_format).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.