microsoftgraph / microsoftgraph/msgraph-sdk-python

Proxy is not respected

Ouverte
#535 3 commentaires 2 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

bug
Langage dominant
Python
Étoiles
630
Forks
96
Merge moyen
15 h 20 min
PR mergées (30 j)
3

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par GraphClientFactory.create_with_default_middleware et GraphRequestAdapter, puis comparez la requête directe de AsyncClient avec la requête de GraphServiceClient. Reproduisez le délai d’attente avec la configuration de proxy fournie et vérifiez si l’AsyncClient configuré est conservé à travers le middleware et l’adaptateur. Le travail est terminé lorsque les requêtes Graph utilisent le proxy configuré au lieu d’expirer.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
azure, python
Domaine
api, networking
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.