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

Add support for Proxies #409

Open
pranitbauva1997 opened this issue Oct 22, 2017 · 10 comments
Open

Add support for Proxies #409

pranitbauva1997 opened this issue Oct 22, 2017 · 10 comments
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@pranitbauva1997
Copy link

I have to use sendgrid to send newsletter mails. Being under a institute proxy, I have to SSH into a AWS server and then pull my script+data there and then send my mails from there.

Now I understand this feature isn't that a big improvement, but this would really help me. I want to make this fix in this package.

What are your opinions?

@mbernier mbernier added hacktoberfest and removed difficulty: hard fix is hard in difficulty difficulty: medium fix is medium in difficulty difficulty: very hard fix is very hard in difficulty labels Oct 27, 2017
@mbernier
Copy link
Contributor

mbernier commented Oct 28, 2017

Go for it!! If this is something that you need, someone else might need it to. Please make a PR of your change, so long as it is documented, configurable, testable, and passes our build and testing - we will get it merged in.

@thinkingserious thinkingserious added type: community enhancement feature request not on Twilio's roadmap status: work in progress Twilio or the community is in the process of implementing difficulty: medium fix is medium in difficulty and removed help wanted labels Feb 27, 2018
@campbellmc
Copy link

I guess this would need ProxyHandler added in python_http_client first or at the same time, right?
https://github.com/sendgrid/python-http-client/blob/master/python_http_client/client.py

Would the intention be to add proxies kwargs when instatiating SendGridAPIClient ? And then pass the kwargs through to python_http_client Client?

@thinkingserious
Copy link
Contributor

Hi @campbellmc,

Yes, that is correct. Thanks!

@splashx
Copy link

splashx commented Mar 1, 2019

@thinkingserious May I ask why is opts deprecated? And how opts distinguishes from the proposal from @campbellmc above?

def __init__(
self,
apikey=None,
api_key=None,
impersonate_subuser=None,
host='https://api.sendgrid.com',
**opts): # TODO: remove **opts for 6.x release
"""

@adam-revops
Copy link

Looking through the code I didn't find support for proxy-based integrations. Are you still taking PRs for this open request?

@campbellmc
Copy link

As a side-note - we worked around this by calling requests.post independently.
We construct the payload using the sendgrid helpers and then go our own way with the actual request - like this - which included proxies we needed in a dict:

r = post(https_url, headers=headers, auth=(provider.api_key, provider.api_secret), json=payload, proxies=self.proxies)

Alas, time is short to make a PR but this work-around was shorter so you can guess which won.

@splashx
Copy link

splashx commented Sep 8, 2019

requests support environmental variables http_proxy and https_proxy, we thought we would also need to patch this up but we just didn’t, just export the envs and sendgrid-python will work.

@adam-revops
Copy link

adam-revops commented Sep 8, 2019

Thanks @campbellmc, thats a good work-around!

@splashx Thats a good suggestion, although we don't want to proxy all of our daemon's network requests through the specific proxy we are using because of network costs. These proxy requests are for running it through a secure tokenizer for email addresses and other PII to be revealed to sendgrid.

@thinkingparticle
Copy link

thinkingparticle commented Apr 18, 2020

as an example of how to build a request with proxies:

send_grid_api_client = SendGridAPIClient("YOUR API KEY")
tmp_url = send_grid_api_client.client.mail.send._build_url(query_params={})
headers = send_grid_api_client.client.request_headers
req_body = {'from': {'email': '[email protected]'},
                     'subject': 'my_subject',
                     'personalizations': [{'to': [{'email': 'example_reciever@example_reciever.com'}]}],
                     'content': [{'type': 'text/plain', 'value': 'my_message'}]}

import requests as rq
req = rq.post(url=tmp_url,
       json=req_body,
       headers=headers,
       proxies={"http":"my_http_proxy","https":"my_https_proxy"}
       timeout=10
             )
req.status_code==202

the above code might not be good in production.

@chrisdlangton
Copy link

@childish-sambino childish-sambino added status: help wanted requesting help from the community and removed status: work in progress Twilio or the community is in the process of implementing labels Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

9 participants