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
Support clients behind a proxy #81
Comments
gspread does not handle proxies at the moment. Although I'm not planning to implement it I've received an email several hours ago from a guy who has similar issue and considering to implement proxy handling. So stay tuned. I haven't used proxies myself with gspread, but from what I can see on Stack Overflow, httplib does support proxies. The issue in this case is with gspread's |
Found out that question on stack overflow. I'll also try to work on it. In the meantime I'll find a workaround :) |
You might want to set both http_proxy and https_proxy system variables. I've been doing so and it works. |
Environment variables don't work for me. Although they work for requests. @burnash, what do you think of replacing httplib/http with requests? |
any update on this? |
+1 |
2 similar comments
+1 |
+1 |
After a quick search I found this article on medium.com => here which mention the classic way of proxy handling for command line tools: use the env var Proxy is a network feature, and specific to the local environment. Proxy is a system setting, so may be in the library used to send HTTP requests we'll find some proxy handling (I will look into it) but for sure it is something you set in your system, in you terminal and one will make it work very very much faster this way than patching GSpread. |
I just checked the HTTP decorator used by GSpread: https://github.com/googleapis/google-auth-library-python It should now work, I don't have a setup with a proxy already setup to test it, if anyone is up for testing this, feel free to comment your result 🙂 |
Could you point me to the decorator please? |
yep, you can fin dit using the link above to |
So the issue I have is that I do not want connection to the proxy across all http sessions, only those where I am making requests outside my internal network. This is why I am looking for a library-specific solution rather than environment-wide. e.g. there are certain APIs that I do not want to connect to via proxy, and some that I do, this being one of them. |
I figured out a solution - I discovered the env variable |
pleasure. I'm glad it works. if you are using linux, remember these env variables works for other software/libraries too (it might work as well on MacOS, can't telle about Windows though). |
Hey, I already set both env but the issue is still there 😭 |
Hi, how do you set |
Hi so it could look like this: About the |
Hi, this works for me.
|
How to install a proxy for gspread only: import requests
from requests.adapters import HTTPAdapter
from google.auth.transport.requests import AuthorizedSession, Request
auth_request_session = requests.Session()
auth_request_session.mount("https://", HTTPAdapter(max_retries=3))
session = AuthorizedSession(
gspread.client.convert_credentials(credentials),
auth_request=Request(auth_request_session),
)
if proxy_url:
session.proxies.update({'https': proxy_url})
auth_request_session.proxies.update({'https': proxy_url})
gspread = gspread.Client(auth=None, session=session) |
Hi! Your code did not work. Session and credentials was not defined. Can you demonstrate this? |
@Ousman1301 Was this question for me? What exactly is not working? |
Never mind, I just made a mistake! Thank you soooooooooo much!! |
Hi,
maybe I am missing something super easy but... I can't manage to log in when standing behind a proxy. I tried to set up environment variables without success. Googling a bit it seems httplib is not handling proxy that well. Maybe that's the issue.
Thanks for this great lib!
The text was updated successfully, but these errors were encountered: