Export sharepoint list data to excel using python - python

I have sharepoint url where i can open and export that sharepoint list into excel. I want to automate that using python. i have tried many suggestions from online. but none of those are working.
i have tried below code to connect sharepoint
import requests
url= 'my sharepoint file path here'
r=requests.get(url,verify=False) #no username or password required
i am expecting the code should export sharepoint list data to new excel file.

I haven’t done this myself with code, but I believe it should work similar to what’s been done in SharePoint 2013: Export To Excel Using REST API
What they do there is actually using a link to a query that Excel can understand with parameters as the list id and view id. Since they use code within the browser it recognizes the content type (.iqy file) as something that should be opened in Excel. Don’t know how that would be when dont in Python though.
Another thing: Unless you have anonymous access turned on in your site, you need to authenticate the request to SharePoint.

Related

Sharepoint API how to read file havin only sharing link to it

I'm using python office365 library to access sharepoint documents. I don't know how to access file via API that have been shared with me by sharing link. I need to get this file content and if possible metadata (last modify date). Could anyone help?
The user that I'm using have no access to this sharepoint folder other than a sharing link to a single file.
I tried many variations of normal file access API, bot by hand and by office365 library. I couldnt find a way to access a file when I have only sharing link to it.
My sharing link looks like that:
https://[redacted].sharepoint.com/:x:/s/[redacted]/dir1/dir2/ESd0HkNNSbJMhQFavQsr9-4BNHC2rHSWsnbs3zRdjtZsC3g so there is not really a filename here and I cannot read via API content of any folder per se because I have an error Attempted to perform an unathorized operation.. Authentication goes fine (when i mistake password I get different error).
According to my research and testing, you can use the following Rest API to read file (get file content):
https://xxxx.sharepoint.com/sites/xxx/_api/web/GetFolderByServerRelativeUrl('/sites/xxx/Library_Name/Folder Name')/Files('Document.docx')/$value
If you want to get last modify date, you can use the following Rest API to get the Modified field:
https://xxxx.sharepoint.com/sites/xxx/_api/web/lists/getbytitle('test_library')/Items?$select=Modified

Python sharepoint connection - unable to access

I am trying to access my sharepoint site using python. The sharepoint URL looks something like this: https://companyname.sharepoint.com/teams/mysitename. Following tutorials online on creating sites in sharepoint, somehow my site URL becomes https://companyname.sharepoint.com/teams/mysitename instead of https://companyname.sharepoint.com/sites/mysitename and this causes an issue trying to create the sharepoint-python connection.
I am referring to this document https://shareplum.readthedocs.io/en/latest/tutorial.html. The methods used in the document do not work when the domain name uses 'teams' instead of 'sites'. Would appreciate any help. Thanks!

get dropbox file content using dropbox URL

I have dropbox filepicker in my project, once user select file i am receiving URL of the dropbox, now i want a content of that file using that URL in python.
here is the link which i received from dropbox picker : https://www.dropbox.com/s/ocissavtfvvdh2g/images.png?dl=0
I have checked this link https://sodocumentation.net/dropbox-api/topic/408/downloading-a-file, but it will ask for the path, but i don't have path of the file, i just have URL of the file
I just have to use 1 in dl querystring.
https://www.dropbox.com/s/ocissavtfvvdh2g/images.png?dl=1 like this
I would suggest you to use Dropbox API for your project. I made a similar project but using Google Drive API.
Check bellow
https://www.dropbox.com/developers/documentation/python#install
It sounds like you're using the Dropbox Chooser. If you just want direct access to the data of the selected file(s), you should use the "direct" link type.
Based on your sample link, I see that you're currently using the "preview" link type, which doesn't link directly to the file data, but rather a preview page.
Also, the sample code you linked to is for accessing files via the Dropbox API with an access token, not using a link returned by the Chooser, so it isn't relevant.
If you switch to the "direct" link type, you can use the returned link to directly access the file data just with an HTTP GET request, for four hours.
Alternatively, if you need access for longer than that, you can keep using the "preview" link type but modify the link as documented here.

gspread.exception Spreadsheet not Found on a particular sheet

I am working to get google sheets downloaded on my EC2 linux server.I shared the google sheet with email id from credentials json file. I am using gspread, to open the sheet using open_by_key(file['id']) and the code works when I run using root but not using a different user having the same properties. It gives this error :
File "/home/edh/.local/lib/python2.7/site-packages/gspread/client.py",
line 113, in open_by_key
raise SpreadsheetNotFound
gspread.exceptions.SpreadsheetNotFound
This code works in team drives too. The weird thing is I am able to run this code over different google sheets in the same user of EC2, but this particular sheet gives the above error.
Please help and let me know if you need any more info from my side.

Dump data from python cron job to google spreadsheets

I am creating a CSV which contains the report as a result of a cronjob. I want to share this CSV via Google spreadsheets - the report itself is versioned, so I would just dump the CSV contents into the same worksheet in the same spreadsheet each and every single time.
I have found gspread which looked very promising but unfortunately gives me NoValidUrlKeyFound Errors. The Python example for interacting with the Spreadsheets API v4 (to be found here) requires interactivity because of the OAuth flow.
Can someone point me in the right direction? Ideally I would just do:
client = spreadsheet.client(credential_file)
client.open_spreadheet(url_or_something).open_worksheet(0).dump(csv)
print("Done")
I have found the answer in a Github issue:
Using gspread, follow the official guide to receive an oauth token. You will end up with a JSON file holding the credentials.
In order to access a spreadsheet with these credentials however, you need to share the spreadsheet with the account represented by them. In the JSON file there is a property client_email. Share the document with that e-mail address and voila, you'll be able to open it!

Categories

Resources