Connection through proxy
Hello! First of all I would like to say thank you for you package! It's very usefull for me! Great job. I use it from my working place and my organization uses proxy to connect users to the internet. I was unable to connect. The reason was in sso.py module. It will not pass any http.Client configuration during requests.get(OAUTH_CONSUMER_URL).json(). So I modified this part of code to this: OAUTH_CONSUMER = requests.get(OAUTH_CONSUMER_URL, proxies=parent.proxies, verify=parent.verify).json() Everything works for me now. Maybe it could be the case for other users behind a proxy.
class GarminOAuth1Session(OAuth1Session): def init( self, /, parent: Optional[Session] = None, **kwargs, ): global OAUTH_CONSUMER if not OAUTH_CONSUMER: OAUTH_CONSUMER = requests.get(OAUTH_CONSUMER_URL).json() super().init( OAUTH_CONSUMER["consumer_key"], OAUTH_CONSUMER["consumer_secret"], **kwargs, ) if parent is not None: self.mount("https://", parent.adapters["https://"]) self.proxies = parent.proxies self.verify = parent.verify
did you already try the following?
garth.configure(proxies={"https": "https://myproxy"})
Yes, sure. Without doing this the the valuable "parent: Optional[Session] = None" will not have any info about proxy or certificate check. So it is mandatory. You can try it yourself.
- Set up a proxy using garth.configure(proxies={"https": "https://myproxy"}).
- Open session.py module, find request definition (def request...). You will see a code like this below:
req = Request( method=method.upper(), url=url, headers=headers, files=files, data=data or {}, json=json, params=params or {}, auth=auth, cookies=cookies, hooks=hooks, ) prep = self.prepare_request(req)
proxies = proxies or {}
- Try to put a breakpoint on proxies = proxies or {}
- Check the proxies value. It will be empty
But if you modify your code like I said before (OAUTH_CONSUMER = requests.get(OAUTH_CONSUMER_URL, proxies=parent.proxies, verify=parent.verify).json()), the proxies will contains a dictionary with your proxy settings.
Interesting ... I'll try to reproduce and make the change. I'll get to it this weekend.
Hi @matin, I can confirm that only if using @MikhailNaumenko patch is allowing to connect to oauth provider via https proxy: sso.py:
OAUTH_CONSUMER = requests.get(OAUTH_CONSUMER_URL,
new: proxies=parent.proxies, verify=parent.verify).json()