microsoftgraph / microsoftgraph/msgraph-sdk-python
Proxy is not respected
未关闭
还没有人认领这个 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 GraphClientFactory.create_with_default_middleware 和 GraphRequestAdapter 开始,然后比较直接的 AsyncClient 请求与 GraphServiceClient 请求。使用提供的代理配置重现超时,并跟踪已配置的 AsyncClient 是否在 middleware 和 adapter 中得以保留。完成标准是 Graph 请求使用已配置的代理,而不是发生超时。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- azure, python
- 领域
- api, networking
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100