python 3有问题吗?
你好,
它应该与 Python 的两个版本兼容:2 和 3,但让我验证一下。 会回复你的。
您好 感谢您的及时回复。
下面是我得到的错误
`------------------------------------------------- --------------------------
ModuleNotFoundError 追溯(最近一次调用最后一次)
1 导入 json
2
----> 3 从 office365.runtime.auth.authentication_context 导入 AuthenticationContext
4 从 office365.runtime.client_request 导入 ClientRequest
5 从 office365.runtime.utilities.request_options 导入 RequestOptions
ModuleNotFoundError: 没有名为“office365”的模块
是的,我有 pip 安装模块:)
嗨,我已经编写了代码来仅使用请求模块来获取信息。 我可以成功获取 FedAuth 和 rtFa cookie。 但是,当我尝试获取 siteUsers 时,它会引发错误 Forbidden。
你能帮忙吗?
`导入请求
url=" https://login.microsoftonline.com/extSTS.srf "
标头 = {'内容类型':'应用程序/json'}
TopLevelUrl=' https://XXXX.sharepoint.com '
path='C:\PSR\PythonFiles\SharePointOnlineXML.txt'
文件内容 = 打开(路径,'r')
SharepointOnlineAuth = filecontent.read()
SharepointOnlineAuth=SharepointOnlineAuth.format('[email protected]','Password',TopLevelUrl)
response=requests.post(url,data=SharepointOnlineAuth,headers=headers)
s=str(response.content)
Start = [pos for pos in range(len(s)) if s[pos:].startswith('
Finish= [pos for pos in range(len(s)) if s[pos:].startswith('
登录响应=s[开始+40:完成]
url=TopLevelUrl+'/_forms/default.aspx?wa=wsignin1.0'
headers = {'content-type': 'application/x-www-form-urlencoded'}
response=requests.post(url,data=LoginResponse,headers=headers)
url=TopLevelUrl+'/_api/web/siteusers'
打印(网址)
_Fedauth='FedAuth={}'.format(response.cookies['FedAuth'])
_rtFa='rtFa={}'.format(response.cookies['rtFa'])
_FinalDict={'Cookie':_Fedauth+','+_rtFa}
headers = {'Content-Type': 'application/x-www-form-urlencoded',
'用户代理':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'}
headers.update(_FinalDict)
response=requests.get(url,headers=headers)
打印(响应)`
在python3.4上出现错误:
_Traceback(最近一次通话):
文件“auth_sharepoint_online365.py”,第 2 行,在
从 office365.runtime.auth.authentication_context 导入 AuthenticationContext
文件“authentication_context.py”,第 2 行,在
从 office365.runtime.auth.saml_token_provider 导入 SamlTokenProvider
文件“saml_token_provider.py”,第 2 行,在
导入 urlparse
导入错误:没有名为“ urlparse ”的模块_
根据https://docs.python.org/2/library/urlparse.html :
urlparse 模块在 Python 3 中重命名为 urllib.parse。
试试这个https://github.com/parthrawal/Python.O365我已经编写了可以连接到 SharePoint Online 的 .py 文件,甚至有一些方法可以从字典格式的列表中获取数据。 如果您需要任何帮助,请告诉我。
@vic-by 最近的提交解决了这个问题: https :
请注意,此时此提交尚未推送到 pypi。 因此,如果您执行pip install Office365-REST-Python-Client
您将不会获得该代码。 从 git 安装将: pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git
仍然需要做一些工作才能真正使用 python 3 获取库。
我在 python 3 下运行库时遇到了编码问题。它在执行 list.properties 时发生,但我确定问题是普遍存在的。
ctx = ClientContext(url, ctx_auth)
web = ctx.web
ctx.load(web)
ctx.execute_query()
lists = web.lists
ctx.load(lists)
ctx.execute_query()
lists[0].properties
in <module>()
---> 16 lists[0].properties
c:\python\python35\lib\encodings\cp850.py in encode(self, input, final)
17 class IncrementalEncoder(codecs.IncrementalEncoder):
18 def encode(self, input, final=False):
---> 19 return codecs.charmap_encode(input,self.errors,encoding_map)[0]
20
21 class IncrementalDecoder(codecs.IncrementalDecoder):
UnicodeEncodeError: 'charmap' codec can't encode character '\u2019' in position 11052: character maps to <undefined>
我在 Python 3 中遇到了同样的问题:“ModuleNotFoundError:没有名为‘urlparse’的模块”
测试文件 SharePointOnline.py:身份验证失败 -> 输入和存储的密码不匹配。
您是否尝试过此链接https://github.com/parthrawal/Python.O365确保您使用相同的服务帐户
是的。 复制/粘贴代码,在底部:
if __name__ == "__main__":
UserName = "[email protected]"
# UserName = "[email protected]"
Password = "my_password"
TopLevelUrl = "https://company.sharepoint.com/"
SPOnlineHeaders(UserName, Password, TopLevelUrl)
返回以下错误:
....
IndexError: list index out of range
为了获得有关错误的更多详细信息,我在 SPOnlineHeaders 上插入了以下代码(打印):
response = requests.post(url, data=SharepointOnlineAuth, headers=headers)
s = str(response.content)
print(s)
回复:
... wst:FailedAuthentication...输入的和存储的密码不匹配...
我希望您使用的是服务帐户
那是正确的。 我正在使用服务帐户。
密码正确吗? 你能仔细检查一下吗? 因为我尝试运行代码,它工作正常。 但是当我输入错误的密码时,它会抛出“IndexError: list index out of range”错误。
是的。 密码正确。 这就是手动登录时发生的情况。
我将链接写入浏览器: https :
当按回车时,我被重定向到登录页面: https :
在登录页面按下确定按钮后,我看到了两个快速链接......
首先: https :
... 和 ...
第二个: https://login.microsoftonline.com/login.srf?client-request-id=...
最后停在所需页面:
https://company.sharepoint.com/
我运行此代码发现它在代码中的某处抛出 403 错误。
response = requests.post(url,data=SharepointOnlineAuth,headers=headers)
s = str(响应.内容)
印刷)
“b'403 禁止'”
我忘了使用端点
网址
我在使用 urlparse(Python 3.6.5 :: Anaconda, Inc.)时遇到了同样的问题。 这是通过修改 saml_token_provider.py 解决的: from urllib.parse import urlparse [...] url = urlparse(self.url)
然后我丢失了 web,我用它安装了它: pip install lpthw.web
。 但是,似乎存在问题,因为现在我遇到了以下问题:
from web import Web
File "C:\ProgramData\Anaconda3\lib\site-packages\web\__init__.py", line 14, in <module>
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
ModuleNotFoundError: No module named 'utils'
在 anaconda 中安装 utils 模块。
在 anaconda 中安装 utils 模块。
谢谢。 安装 utils 后,我还需要安装 db...在包中检查 requirements.txt 可能有用吗?
现在发生的事情是打印语句不适用于 python3:
print "var", var
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("var", var)?
@viogp感谢您在这里发布您的进展,如果我们能解决其中的一些问题,那就太好了。 目前正在 py 2.7 中使用这个库,并希望将这些工作流转移到 py 3。
你好。 我在使用这个库时遇到问题。
检索令牌时出错:AADSTS90023:STS 请求无效。
检索身份验证 cookie 时出错
返回 'FedAuth=' + self.FedAuth + '; rtFa=' + self.rtFa
类型错误:只能将 str(不是“NoneType”)连接到 str
任何人都可以帮助我?
由于该库正式兼容 Python 2 和 Python 3 运行时,建议关闭此问题。
你好,
当我在运行期间在 pycharm 中使用项目环境时,我收到此错误“ModuleNotFoundError: No module named 'office365.sharepoint.client_context'”。 但是如果我使用 Python 系统环境它会工作得很好。 我使用 Python 3.6 或 3.7 的行为相同。
请帮忙!
谢谢。
最有用的评论
@vic-by 最近的提交解决了这个问题: https :
请注意,此时此提交尚未推送到 pypi。 因此,如果您执行
pip install Office365-REST-Python-Client
您将不会获得该代码。 从 git 安装将:pip install git+https://github.com/vgrem/Office365-REST-Python-Client.git