使用ms-graph-python-client出现scopes意外参数TypeError如何解决
问题原因
报错TypeError: __init__() got an unexpected keyword argument 'scopes'是因为areed1192/ms-graph-python-client库的MicrosoftGraphClient类构造函数本身不接收scopes关键字参数,你将scopes放在了错误的传参位置。
解决方法
按以下步骤修改代码即可正常运行:
- 保留你定义的scopes列表不变,删除
MicrosoftGraphClient实例化时传入的scopes=scopes参数 - 将
scopes作为参数传入login()方法中
修改后的完整代码如下:
import configparser from unittest import TestCase from configparser import ConfigParser from ms_graph.client import MicrosoftGraphClient scopes = [ 'Calendars.ReadWrite', 'Calendars.ReadWrite.Shared', 'Directory.Read.All', 'Directory.ReadWrite.All', 'Files.ReadWrite', 'Files.ReadWrite.All', 'Notes.ReadWrite.All', 'offline_access', 'User.Read', 'User.Read.All', 'User.ReadWrite.All' ] Config = ConfigParser() Config.read(r'B:/New_folder/Graph_Download/Secret.ini') client_id = Config.get('graph_api', 'client_id') client_secret = Config.get('graph_api', 'client_secret') redirect_uri = Config.get('graph_api', 'redirect_uri') Mgraph_client = MicrosoftGraphClient( client_id= client_id, client_secret= client_secret, redirect_uri= redirect_uri, credentials= 'B:/New_folder/Graph_Download/Settings.jsonc' ) Mgraph_client.login(scopes=scopes)
补充验证
如果修改后仍有初始化参数报错,可以检查你安装的库版本是否为最新正式版,执行以下命令更新到最新版本即可:pip install --upgrade ms-graph-python-client
内容的提问来源于stack exchange,提问作者Swarup
相关产品推荐
相关产品推荐

