azure 如何修复属性错误:模块'graph'没有属性'get_user_token'

aurhwmvo  于 2022-11-30  发布在  其他
关注(0)|答案(1)|浏览(108)

我已经导入了图形,知道为什么它不能识别属性吗?

def display_access_token(graph: Graph):
    token = graph.get_user_token()
    print('User token:', token, '\n')

if user_input == '0':
    display_access_token(graph)

我不知道该怎么做才能解决它。提前感谢。

1szpjjfi

1szpjjfi1#

我已经参考了official documentation的示例代码。在我这边复制之后,在graph.py中添加get_user_token()之后,这是工作正常的。下面是我的graph.py中的完整代码。

import json
from configparser import SectionProxy
from azure.identity import DeviceCodeCredential, ClientSecretCredential
from msgraph.core import GraphClient

class Graph:
    settings: SectionProxy
    device_code_credential: DeviceCodeCredential
    user_client: GraphClient
    client_credential: ClientSecretCredential
    app_client: GraphClient

    def __init__(self, config: SectionProxy):
        self.settings = config
        client_id = self.settings['clientId']
        tenant_id = self.settings['authTenant']
        graph_scopes = self.settings['graphUserScopes'].split(' ')

        self.device_code_credential = DeviceCodeCredential(client_id, tenant_id = tenant_id)
        self.user_client = GraphClient(credential=self.device_code_credential, scopes=graph_scopes)
        
    def get_user_token(self):
        a="Return from get_user_token"
        return a
  • 结果:*

相关问题