microsoftgraph / microsoftgraph/msgraph-sdk-python

Proxy is not respected

未關閉
#535 3 則留言 2 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

bug
主要語言
Python
星號
630
分支
96
平均合併
15 小時 20 分鐘
30 天內合併 PR
3

描述

I followed the steps here and its not using the proxy at all. My requests just time out: https://learn.microsoft.com/en-us/graph/sdks/customize-client?tabs=python#configuring-the-http-proxy-for-the-client

While normal requests using httx work, the requests to Azure do not. I'm guessing that this new client is not accepted somewhere down the chain

import asyncio
from azure.identity.aio import ClientSecretCredential
from django.conf import settings
from httpx import AsyncClient
from kiota_authentication_azure.azure_identity_authentication_provider import (
    AzureIdentityAuthenticationProvider,
)
from msgraph import GraphRequestAdapter, GraphServiceClient
from msgraph.generated.users.users_request_builder import UsersRequestBuilder
from msgraph_core import GraphClientFactory


def get_azure_client() -> tuple[GraphServiceClient, AsyncClient]:
    credential = ClientSecretCredential(
        settings.AZURE_TENANT_ID, settings.AZURE_CLIENT_ID, settings.AZURE_CLIENT_SECRET  # type: ignore
    )
    auth_provider = AzureIdentityAuthenticationProvider(
        credential, scopes=["https://graph.microsoft.com/.default"]
    )
    # see: https://learn.microsoft.com/en-us/graph/sdks/customize-client?tabs=python#configuring-the-http-proxy-for-the-client
    httpx_proxies = {
        "http://": settings.INTERNET_PROXY,
        "https://": settings.INTERNET_PROXY,
    }
    http_client = AsyncClient(proxies=httpx_proxies)  # type: ignore
    http_client = GraphClientFactory.create_with_default_middleware(client=http_client)
    adapter = GraphRequestAdapter(auth_provider, http_client)
    return GraphServiceClient(request_adapter=adapter), http_client


async def amain() -> None:
    client, http_client = get_azure_client()
    await http_client.get("https://microsoft.com") # this works
    await client.groups.by_group_id(  # this times out
        settings.AZURE_GROUP_ID
    ).transitive_members.get()


if __name__ == "__main__":
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    try:
        loop.run_until_complete(amain())
    except KeyboardInterrupt:
        pass

/cc @nejch

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 GraphClientFactory.create_with_default_middleware 和 GraphRequestAdapter 開始,然後比較直接的 AsyncClient 請求與 GraphServiceClient 請求。使用提供的 proxy 設定重現逾時,並追蹤已設定的 AsyncClient 是否在 middleware 和 adapter 中獲得保留。完成標準是 Graph 請求使用已設定的 proxy,而不是發生逾時。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
azure, python
領域
api, networking
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。