Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection through proxy #66

Open
MikhailNaumenko opened this issue Aug 14, 2024 · 3 comments
Open

Connection through proxy #66

MikhailNaumenko opened this issue Aug 14, 2024 · 3 comments

Comments

@MikhailNaumenko
Copy link

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

@matin
Copy link
Owner

matin commented Aug 14, 2024

did you already try the following?

garth.configure(proxies={"https": "https://myproxy"})

@MikhailNaumenko
Copy link
Author

MikhailNaumenko commented Aug 14, 2024

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.

@matin
Copy link
Owner

matin commented Aug 15, 2024

Interesting ... I'll try to reproduce and make the change. I'll get to it this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants