python-3.x - 如何使用 python 打开浏览器并连接到共享点?
问题描述
我需要将文件从本地 PC 上传到共享点,但对于我的帐户,我启用了 2 因素。如何绕过或使用python进行身份验证并将文件上传到其中?
我尝试了下面的代码,但我不确定它是否正确!
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
import sharepointparameters as parameters
baseurl = 'https://dxcportal.sharepoint.com'
basesite = '/_layouts/15/sharepoint.aspx' # every share point has a home.
siteurl = baseurl + basesite
localpath = "demandsheet.xlsx"
remotepath = "datafiles/demandsheet.xlsx" # existing folder path under sharepoint site.
ctx_auth = AuthenticationContext(siteurl)
ctx_auth.acquire_token_for_user(parameters.username, parameters.password)
ctx = ClientContext(siteurl, ctx_auth) # make sure you auth to the siteurl.with open(localpath, 'rb') as content_file:
file_content = content_file.read()
dir, name = os.path.split(remotepath)
file = ctx.web.get_folder_by_server_relative_url(dir).upload_file(name, file_content).execute_query()
解决方案
推荐阅读
- php - Yii 1.0:如何知道renderPartial是成功还是失败
- c - 即使在三元运算符中给出的左值很好,赋值语句也会出错
- aspnetboilerplate - 如何定义在单元测试执行期间使用的 Abp 语言?
- ruby-on-rails - 何时执行 ActiveRecord 查询?
- ruby-on-rails - Net::OpenTimeout 执行在 Action Mailer Ruby on Rails 5 中过期
- django - django admin 中选择字段的可搜索下拉菜单
- javascript - 在不同的 HTML 标记中显示 javascript 多维数组
- java - Java合并排序递归奇怪
- c - 如何在c中使用数组打开文件
- security - 通过命令行安全地发送密码而不暴露在 ps/wmic (Windows,Unix) 中