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

Plotly stream + corporate proxy with basic auth #1129

Closed
imscaradh opened this issue Aug 23, 2018 · 5 comments
Closed

Plotly stream + corporate proxy with basic auth #1129

imscaradh opened this issue Aug 23, 2018 · 5 comments

Comments

@imscaradh
Copy link
Contributor

I am trying to use Plotly streaming functionality behind a corporate proxy with basic auth. Despite the comprehensible instructions at https://plot.ly/python/proxy-configuration/ I didn't get Plotly up and running. After digging around in my system configuration I noticed that only proxy servername and port is respected while setting up the http tunnel:

self._conn.set_tunnel(server, port)

Was this intentionally implemented in this way? As soon as I add the Proxy-Authorization header to the tunnel configuration everything works like expected.

@jonmmease
Copy link
Contributor

Hi @imscaradh , thanks for reaching out and I'm glad you got things working.

@scjody do you have any thoughts on this scenario, and whether something in plotly.py should be changed?

@scjody
Copy link

scjody commented Aug 23, 2018

@jonmmease It does look like we only use the hostname and port extracted from the HTTPS_PROXY or HTTP_PROXY environment variable, meaning that any other information (username, password) is ignored.

The hostname and port are extracted in

def _get_proxy_config(self):
"""
Determine if self._url should be passed through a proxy. If so, return
the appropriate proxy_server and proxy_port. Assumes https_proxy is used
when ssl_enabled=True.
"""
proxy_server = None
proxy_port = None
ssl_enabled = self._ssl_enabled
if ssl_enabled:
proxy = os.environ.get("https_proxy")
else:
proxy = os.environ.get("http_proxy")
no_proxy = os.environ.get("no_proxy")
no_proxy_url = no_proxy and self._server in no_proxy
if proxy and not no_proxy_url:
p = urlparse(proxy)
proxy_server = p.hostname
proxy_port = p.port
return proxy_server, proxy_port
and used here:
if (proxy_server and proxy_port):
if ssl_enabled:
context = self._get_ssl_context()
self._conn = http_client.HTTPSConnection(
proxy_server, proxy_port, context=context
)
else:
self._conn = http_client.HTTPConnection(
proxy_server, proxy_port
)
self._conn.set_tunnel(server, port)

This could be extended to support performing basic auth with the proxy.

@imscaradh
Copy link
Contributor Author

Hi @jonmmease , I forked plotly.py and committed my changes here: 4c38dc5

I'm not sure this is in your interest. If it is, I will be happy to create a PR.

@jonmmease
Copy link
Contributor

Hi @imscaradh , these changes look reasonable and generally useful so a PR would be great!

I don't have a way to test it personally, but I'll reach out to some other folks to help out there.

Thanks!

@jonmmease
Copy link
Contributor

Done in #1133. Thanks @imscaradh

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

3 participants