I need to get multiple .csv files from SharePoint.
If I make this request via Postman
https://mycompany.sharepoint.com/teams/a/g/_api/web/GetFolderByServerRelativeUrl('Data%20Sources\')/Files('sharepoint_test.csv')/$value
With headers
Authorization: Bearer eyJ...
Accept: application/json;odata=verbose
I get the contents of "test_sharepoint.csv":
column a,column b,column c
32,523,88
46,34,659
25,767,78
I need to download multiple files at once and SharePoint doesn't seem to provide an endpoint for it. So using python and grequests, I get a response, but not the binary data:
>>> base_url = "https://mycompany.sharepoint.com/teams/a/g/_api/web/GetFolderByServerRelativeUrl('Data%20Sources\')/"
>>> url_1 = "Files('sharepoint_test.csv')/$value"
>>> url_2 = "Files('sharepoint_test_2.csv')/$value"
>>> allurls = [base_url + url_1, base_url + url_2]
>>> headers = {"Authorization": authtoken, "Content-Type": "application/json;odata=verbose", "Accept": "application/json;odata=verbose"}
>>> rs = (grequests.get(u, headers=headers, stream=True) for u in allurls)
>>> s = grequests.map(rs)
>>> s
[<Response [200]>, <Response [200]>]
>>> data = open(s[0], "rb").read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: expected str, bytes or os.PathLike object, not Response
How can I actually get the binary data via grequests
?