pywin32 - 未找到 win32com 模块

问题描述 投票:0回答:1

我尝试将 Web 服务部署到 azure 门户(linux)。但是,我的应用程序服务无法正常工作,并且显示“ModuleNotFoundError:没有名为“win32com”的模块”。我相信 win32com 不兼容 Linux,仅适用于 Windows。

我正在研究这些参数:

from win32com import client as Client

outlook = Client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
user_info = outlook.CreateRecipient(user).AddressEntry
office_location = user_info.GetExchangeUser().StateOrProvince
email_address = user_info.GetExchangeUser().PrimarySmtpAddress
manager_name = user_info.GetExchangeUser().GetExchangeUserManager().Name
manager_email = user_info.GetExchangeUser().GetExchangeUserManager().PrimarySmtpAddress

将感谢您的想法

python linux windows winapi
1个回答
0
投票

直接使用 win32com 访问 Outlook 的

MAPI
可能是不可能的。我不知道您的组织是做什么的,但可以制作一个简单的函数来使用 Outlook REST API 提取响应。 -不确定是否有效。

import requests
import json

def get_user_info(access_token):
    """Fetches user information using the Outlook REST API.

    Args:
        access_token (str): The OAuth 2.0 access token.

    Returns:
        dict: A dictionary containing user information.
    """

    # Replace with the appropriate endpoint to get user details
    user_info_endpoint = "Your Outlook REST API Endpoint address"
    headers = {
        "Authorization": f"Bearer {access_token}"
    }

    response = requests.get(user_info_endpoint, headers=headers)

    if response.status_code == 200:  #Ensuring valid http response.
        user_data = json.loads(response.text)
        
        # Extract required information
        office_location = user_data.get("officeLocation", "")
        email_address = user_data.get("emailAddresses")[0].get("address", "")  # Assuming first email address
        manager = user_data.get("manager")
        manager_name = manager.get("displayName", "") if manager else ""
        manager_email = manager.get("emailAddress", {}).get("address", "") if manager else ""

        return {
            "office_location": office_location,
            "email_address": email_address,
            "manager_name": manager_name,
            "manager_email": manager_email
        }
    else:
        raise Exception(f"Error fetching user information: {response.text}")
© www.soinside.com 2019 - 2024. All rights reserved.