Seek your guidance, I am new #Python and in learning phase.
Problem Statement: I want to connect & Download the xlsx file from my office SharePoint 2013 site.
Steps so far:
import sharepy
s = sharepy.connect("https://office.XXX.com/sites/pkdyns")
r = s.getfile("https://office.XXX.com/sites/pkdyns/Shared%20Documents/YYYY.xlsx")
r = s.getfile("https://office.XXX.com/sites/pkdyns/Shared%20Documents/YYYY.xlsx", filename="/PYTHON/YYYY.xlsx")
After this I dont see the downloaded file, not sure if it ran or not, using Jupyter Notebook but it didnt throw up any error. Please suggest.
sharepy library seems to only support sharepoint online.
SharePy - Simple SharePoint Online authentication for Python
Below is a sample about how to download file from sharepoint, you may take a reference( it uses another library):
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.file import File
ctx = ClientContext.connect_with_credentials(url,UserCredential(username, password))
web = ctx.web
ctx.load(web)
ctx.execute_query()
print "Web title: {0}".format(web.properties['Title'])
path = "../../tests/data/SharePoint User Guide.docx"
response = File.open_binary(context, "Shared Documents/SharePoint User Guide.docx")
response.raise_for_status()
with open(path, "wb") as local_file:
local_file.write(response.content)
Related
I'm trying to write a python script to automatically grab a pdf snapshot of a Kibana dashboard and upload it to a website called Jira.
I've worked out the part of uploading a pdf stored locally to Jira via python, however I need to remove the step of having to download the pdf to my computer and then open it in python (i.e., a function that opens a link from Kibana to the pdf). Is this possible?
from jira import JIRA
import requests
# Server Authentication
username = xxxxxxx
password = xxxxxxx
options = {'server': 'https://yourhostname.jira.net'}
jira = JIRA(options = options, auth = (username, password))
issue = jira.issue('PROJ-1000')
# Upload the file
with open('/some/path/attachment.pdf', 'rb') as f:
jira.add_attachment(issue=issue, attachment=f)
This code that I've been using works for attaching a pdf that I have stored locally, but I would like to be able to grab a pdf dashboard report directly from Kibana without having to store the pdf on my computer first.
I am trying to connect to sharepoint from python, to upload files. Right now the problem is that I am not sure if I am connecting correctly.
I am following this code : https://github.com/bashamsc/sharepoint_python/blob/main/sharepoint_read_file_python.py
#pip install Office365-REST-Python-Client
#Importing required libraries
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
from office365.sharepoint.files.file import File
#Constrtucting SharePoint URL and credentials
sharepoint_base_url = 'https://mycompany.sharepoint.com/sites/sharepointname/'
sharepoint_user = 'user#anothercompany.com'
sharepoint_password = 'pwd'
folder_in_sharepoint = '/sites/sharepointname/Shared%20Documents/YourFolderName/'
#Constructing Details For Authenticating SharePoint
auth = AuthenticationContext(sharepoint_base_url)
auth.acquire_token_for_user(sharepoint_user, sharepoint_password)
but in the executing the last line in jupyter notebook,I got:
An error occurred while retrieving auth cookies from
https://mycompany.sharepoint.com/_forms/default.aspx?wa=wsignin1.0
Following that link, it tells me, in the last line:
Issue Type: Guest user is signing-in but external sharing is disabled.
I dont know what to do, to have a successful connection list and upload files in the SharePoint folder.
I might have a permission problem, in Change the organization-level external sharing setting, the error message looks like "only people in your organization" from https://learn.microsoft.com/en-us/sharepoint/turn-external-sharing-on-or-off . The email I am using does not belong to mycompany.com (who owns the SharePoint), it comes from another company.
Is there anyway around this? Am I correct to think that something have to be change in the SharePoint permission to be able to connect?
As a newbie in python I'm trying to download a single file from my dropbox account. I've got the Dropbox token from developer account and I am not getting how can I use this token in python code. Moreover, I have no idea how can I get a Dropbox path to download files. The code is following:
def download_file():
dbx = dropbox.Dropbox(DROPBOXTOKEN)
# Check that the access token is valid
try:
dbx.users_get_current_account()
except AuthError as err:
sys.exit("ERROR: Invalid access token; try re-generating an access token from the app console on the web.")
with open("//", "w") as f:
metadata, res = dbx.files_download(path=DROPPATH)
f.write(res.content)
Please guide me in detail how can I use here dropbox access token and how to get dropbox path
This is one way to open a file from your Dropbox account.
"Prime_Numbers.txt" is an example of a sample file located in dropbox.
Could you please modify your code to something like this?
import dropbox
dbx = dropbox.Dropbox("<ACCESS_TOKEN>")
with open("Prime_Numbers.txt", "wb") as f:
metadata, res = dbx.files_download(path="/Homework/math/Prime_Numbers.txt")
f.write(res.content)
You can find how to locate your dropbox file path depending on your system by reading this article. https://help.dropbox.com/installs-integrations/desktop/locate-dropbox-folder
I don't know much of anything about SharePoint, but was tasked to use Python to download a SharePoint list. SharePoint is Office365 and is accessed with Single Sign-on. I found the below sample on how to connect to SharePoint:
from office365.runtime.auth.user_credential import UserCredential
from office365.sharepoint.client_context import ClientContext
ctx = ClientContext('https://<site>.sharepoint.com').with_credentials(UserCredential('domain\\user', 'password'))
web = ctx.web
ctx.load(web)
ctx.execute_query()
print(web.properties["Url"])
When executing this code I receive the following error:
Cannot get binary security token for from https://login.microsoftonline.com/extSTS.srf
KeyError: 'FedAuth'
Can anyone point me in the right direction?
Recently when I was searching for similar kind of solution, I found something useful, you can check below code on github.
https://github.com/vgrem/Office365-REST-Python-Client
I've successfully attached a file to a existing issue via JIRA rest api using python :
from jira.client import JIRA
jira = JIRA(basic_auth=([username], [password]), options={'server': [our_jira_server]})
issue = jira.issue([issue_id])
file = open('test.txt')
attachment_object = jira.add_attachment(issue,file)
But instead of local filepath , I need the file to be fetched from remote url. (Let's say google drive)
I 've read the this document , but no help. If python implementation is there, its awesome ..But curl implementation would do good too.
Thanks in advance.