msgraph-sdk-python-core icon indicating copy to clipboard operation
msgraph-sdk-python-core copied to clipboard

HTTP Proxy

Open samwelkanda opened this issue 3 years ago • 1 comments

Do we need a custom adapter to enable a developer to configure a HTTP proxy that will be used for outgoing requests or can we reuse the default python requests library proxy mechanism.

A sample implementation based on the requests library would look follows:

from msgraphcore import GraphSession

device_credentials = DefaultAzureCredential()
scopes = ['.default']

graph_session = GraphSession(device_credentials, scopes)

# If you need to use a proxy, you can configure it once for the entire `Session`

proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}
graph_session.proxies.update(proxies)

# Or you can also configure individual requests with the `proxies` argument to any request method:

proxies = {
  'http': 'http://10.10.1.10:3128',
  'https': 'http://10.10.1.10:1080',
}

graph_session.get("https://graph.microsoft.com/v1.0/me", proxies=proxies)

AB#9806

samwelkanda avatar Mar 18 '21 13:03 samwelkanda

Hello @samwelkanda , Just wanted to give my 5 cents here: as of September 2023, it seems the Session objects from python-requests library is behaving rather strange. They are taking proxy from system settings it seems and preferring them, even if proxy property of Session object is set. And this Session bug doesn't seem to be going away anytime soon unfortunately. https://docs.python-requests.org/en/latest/user/advanced/#proxies (there's a big red warning section there about this issue) https://github.com/psf/requests/issues/2018

It would be great to have a reliable solution to run Python-MSGraph behind the corporate proxy; at the moment it seems quite a complicated task.

lostpassword avatar Sep 15 '23 10:09 lostpassword

thanks for reporting this issue, we have since released a new version of the SDK which this issue doesn't apply to. We encourage you to migrate to the new version and open a new issue if you still need help

baywet avatar Apr 25 '24 15:04 baywet