how to download a file from sharepoint without an authentication (python) - python

I want to download a public file from office365 sharepoint.
the file can be downloaded and accessed without the need to authenticate.
I have seen many examples of how to download a file with authentication but I didn't find anything that does it without. how can it be done?
I'm working with python 3
and the link is looking like this:
https://XXXX.sharepoint.com/:x:/s/YYYY/ZZZZ?e=KKKK

Related

Unable to render aspx files when uploaded to SharePoint programmatically

I am new to SharePoint. I have written a simple python script that basically connects to SharePoint and uploads files (aspx and other frontend files) from a folder on my local machine to a specific folder on SharePoint site.
To facilitate the script to communicate with the SharePoint, I have a created an App principal under SharePoint using the SharePoint App-Only model. I have done this by calling the appregnew.aspx, example: https://spo.test.com/sites/MYSITE/\_layouts/15/appregnew.aspx , below is the sample page when 'appregnew.aspx' is called
Then, I have provided the below permissions to the App principal through 'appinv.aspx', example - https://spo.test.com/sites/MYSITE/\_layouts/15/appinv.aspx
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web" Right="FullControl"/>
</AppPermissionRequests>
Next, I use the Client ID and Client Secret under the Python script to establish communication with SharePoint and to upload files to a specific folder (folder already exists and is not created by the program) on SharePoint, example path to which files are uploaded: https://spo.test.com/sites/MYSITE/Shared%20Documents/TeamDocs2
Note: This script uses Python library 'Office365-REST-Python-Client' to communicate with SharePoint
The script can successfully authenticate itself and also upload the files to the folder on SharePoint. But then when I manually go to the SharePoint folder and click on the aspx file, example : index.aspx; the file gets downloaded instead of getting rendered.
There is no issue with the file i.e. it is not corrupted because when I manually upload the same file onto the same folder, then there is no issue, the file gets rendered.
In regards to the permissions for the App principal, I've already given 'FullControl' at the scope 'sitecolletion/web' level. I also tried changing the scope from 'http://sharepoint/content/sitecollection/web' to 'http://sharepoint/content/sitecollection', this didn't work as well
Please can somebody help me with this. Thanks in advance
The reason the .aspx page is being downloaded is related to security risk mitigation in SharePoint. If you consider that Javascript (.js) files and .aspx files are executable files in the browser, then it should also be self evident that allowing users to upload such files to SharePoint could pose risk. Because of this, Microsoft has disabled custom script on all modern sites by default. You can choose to overrule this setting, but it should be done with extreme caution.

Python - how to read Sharepoint excel sheet without authentication

I just want to read a excel file in Sharepoint, but with no authentication.
Read a sharepoint excel file using the file link, without a authentication.
If you don't need to authenticate (or program the authentication in), to download, you can try requests.get(url="link")
or you could use selenium, to browse the website, and download the file.
And then you can open it with pandas.

Download google drive file using python in a docker image

I have the access token and file id of the file I need to download. After authenticating the user in a react application and using File picker API, I got both of them.
I need to pass them a python file that can download the file but without user intervention(without user permission )
Any suggestion on how to do it?
I do not have a shareable link. I have the file id and the access token after authentication. I need to download it through another application written in python.
Answers on stack overflow to download drive file using python have to do authentication using OAuth first, but in my case, I need to download the file without authentication

download a file from a website which requires authetication using python

I am trying to download a CSV file from a website using python 2.7. I already found some posting about how to retrieve files.
http://www.blog.pythonlibrary.org/2012/06/07/python-101-how-to-download-a-file/
How do I download a file over HTTP using Python?
However, the site that I am trying to access requires authentication: id and password. I was wondering if anyone out there might share an example of how to download a file with authentication barrier.
You can use requests module, and its documentation.

Downloading a File Protected by NTLM/SSPI Without Prompting For Credentials Using Python on Win32?

I need to download a file on a corporate Sharepoint site using CPython. Existing codebase prevents me from using Ironpython without porting the code, so .NET's WebClient library is out. I also want to download the file without prompting the user to save and without prompting the user for network credentials. I tried other libraries, but they all had short-comings:
urllib2 plus python-ntlm: requires user/pass to be provided
COM automation of Internet Explorer: requires the user to click 'Save'
subprocess using wget or cURL: couldn't get either to authenticate without requesting user/pass
I couldn't find anything in pywin32 that looks like it hooks into urllib2 or provides equivalent functionality. So, is there a way to download the file without requesting credentials and without prompting the user to click 'Save'?
I ended up finding some VB code from a Microsoft support page that uses a function from urlmon.dll I replicated it with a single line of ctypes code and it accomplished exactly what I needed it to do.
ctypes.windll.urlmon.URLDownloadToFileA(0,url,local_file_name,0,0)
url is the location of the resource (in this case, an Excel file on a Sharepoint site)
local_file_name is the local path and name of the file to be saved.
This passed credentials across the wire with no prompts.

Categories