Forums

Cant get Plotly chart_studio to save plot

The exact script runs as expected on my own computer, but I get some not understandable error messages when I try to run it on Pythonanywhere.

This is my script:

import chart_studio
import chart_studio.plotly as py
import plotly.express as px

chart_studio.tools.set_credentials_file(username=myusername, api_key=mykey)
chart_studio.tools.set_config_file(world_readable=True, sharing='public')

fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])

py.plot(fig, filename='test.html', auto_open=False, link=True)

This should make a html file named test.html in https://chart-studio.plotly.com/, but it does not. Instead I get the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 594, in urlopen
    self._prepare_proxy(conn)
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 805, in _prepare_proxy
    conn.connect()
  File "/usr/lib/python3.8/site-packages/urllib3/connection.py", line 308, in connect
    self._tunnel()
  File "/usr/lib/python3.8/http/client.py", line 898, in _tunnel
    raise OSError("Tunnel connection failed: %d %s" % (code,
OSError: Tunnel connection failed: 403 Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/lib/python3.8/site-packages/urllib3/connectionpool.py", line 637, in urlopen
    retries = retries.increment(method, url, error=e, _pool=self,
  File "/usr/lib/python3.8/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.plotly.com', port=443): Max retries exceeded with url: /v2/grids (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/trifektum/.local/lib/python3.8/site-packages/chart_studio/api/v2/utils.py", line 172, in request
    response = requests.request(method, url, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3.8/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3.8/site-packages/requests/adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.plotly.com', port=443): Max retries exceeded with url: /v2/grids (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden')))

Is this happening because I am using a free account? And I try to access a site (probably dash chart studio) that is not white listed?

But there is more:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/trifektum/202009_spx_vs_sma50.py", line 11, in <module>
    py.plot(fig, filename='test.html', auto_open=False, link=True)
  File "/home/trifektum/.local/lib/python3.8/site-packages/chart_studio/plotly/plotly.py", line 276, in plot
    grid_ops.upload(
  File "/home/trifektum/.local/lib/python3.8/site-packages/chart_studio/plotly/plotly.py", line 1087, in upload
    file_info = _create_or_overwrite_grid(payload)
  File "/home/trifektum/.local/lib/python3.8/site-packages/chart_studio/plotly/plotly.py", line 1550, in _create_or_overwrite_g
rid
    res = api_module.create(data)
  File "/home/trifektum/.local/lib/python3.8/site-packages/chart_studio/api/v2/grids.py", line 18, in create
    return request("post", url, json=body)
  File "/usr/lib/python3.8/site-packages/retrying.py", line 49, in wrapped_f
    return Retrying(*dargs, **dkw).call(f, *args, **kw)
  File "/usr/lib/python3.8/site-packages/retrying.py", line 206, in call
    return attempt.get(self._wrap_exception)
  File "/usr/lib/python3.8/site-packages/retrying.py", line 247, in get
    six.reraise(self.value[0], self.value[1], self.value[2])
  File "/usr/lib/python3.8/site-packages/six.py", line 696, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/retrying.py", line 200, in call
    attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
  File "/home/trifektum/.local/lib/python3.8/site-packages/chart_studio/api/v2/utils.py", line 179, in request
    raise exceptions.PlotlyRequestError(message, status_code, content)
chart_studio.exceptions.PlotlyRequestError: No message

As plotly.com is already on our whitelist you'd probably have to configure the third party package that tries to connect with that domain to use proxy. You may take a look at this help page as well.

I am not sure how to go about configuring the third party package to use proxy. Is it another domain I use that is blocked?

Will upgrading my account solve my issue, or is it something else?

I am not sure how to go about configuring the third party package to use proxy.

You need to check the documentation of the package you're using.

Will upgrading my account solve my issue, or is it something else?

Yes, it should as it enables unlimited access to the outside world.

I ave zero luck in figuring this out. I tried setting proxy in-line in the set_credentials_file command and the set_config_file command with no luck.

I also tried to add this in the script:

import os

proxy = "http://user:pass@10.10.1.10:3128/"

os.environ['HTTP_PROXY'] = proxy
os.environ['HTTPS_PROXY'] = proxy

with no luck. Appreciate any pointers in this regard:S

Those variables would already be correctly set and you're using the wrong details anyway. If plotly uses the environment variables then you do not need to set them in your code.

About the whitelisting: It appears that api.plotly.com is not on the whitelist. Send us a link to the API documentation and we'll add it to the whitelist for you.

I would think this is the api documentation: https://plotly.com/python/chart-studio/

We need a link to the page in docs where the API endpoint you want us to whitelist is mentioned explicitly.

Hi,

Has plotly been added to the whitelist since the last message?

If not, I am not sure it is what you need, but here is a link containing some endpoints. https://plotly.com/python/getting-started-with-chart-studio/

@romainbarrot Thank you for your message. Can you please confirm the exact endpoint you would like us to consider adding? Please also note the API endpoint you want us to whitelist need's to be mentioned in the documentation before we can add it.