New to Plotly / Python and Need some Help

Hello,

I have just started Python a few weeks ago and Plotly today. I ultimately am looking to plot a US county map, but in the getting started phase, I am having issues plotting basic plots. I am using Jupyter Notebook from Anaconda.

I am doing the following code with the then resulting error. I assume it is a basically minor error that I cannot figure out.

import plotly
plotly.tools.set_credentials_file(username=‘jtanguay’, api_key=‘keyinhere’)

import plotly.plotly as py
import plotly.graph_objs as go

trace0 = go.Scatter(
x=[1, 2, 3, 4],
y=[10, 15, 13, 17]
)
trace1 = go.Scatter(
x=[1, 2, 3, 4],
y=[16, 5, 11, 9]
)
data = [trace0, trace1]

py.plot(data, filename = ‘basic-line’, auto_open=True)

ERROR:

Error Traceback (most recent call last)
~\anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
440 try:
–> 441 cnx.do_handshake()
442 except OpenSSL.SSL.WantReadError:

~\anaconda3\lib\site-packages\OpenSSL\SSL.py in do_handshake(self)
1906 result = _lib.SSL_do_handshake(self._ssl)
-> 1907 self._raise_ssl_error(self._ssl, result)
1908

~\anaconda3\lib\site-packages\OpenSSL\SSL.py in _raise_ssl_error(self, ssl, result)
1638 else:
-> 1639 _raise_current_error()
1640

~\anaconda3\lib\site-packages\OpenSSL_util.py in exception_from_error_queue(exception_type)
53
—> 54 raise exception_type(errors)
55

Error: [(‘SSL routines’, ‘ssl3_get_server_certificate’, ‘certificate verify failed’)]

During handling of the above exception, another exception occurred:

SSLError Traceback (most recent call last)
~\anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
600 body=body, headers=headers,
–> 601 chunked=chunked)
602

~\anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
345 try:
–> 346 self._validate_conn(conn)
347 except (SocketTimeout, BaseSSLError) as e:

~\anaconda3\lib\site-packages\urllib3\connectionpool.py in _validate_conn(self, conn)
849 if not getattr(conn, ‘sock’, None): # AppEngine might not have .sock
–> 850 conn.connect()
851

~\anaconda3\lib\site-packages\urllib3\connection.py in connect(self)
325 server_hostname=hostname,
–> 326 ssl_context=context)
327

~\anaconda3\lib\site-packages\urllib3\util\ssl_.py in ssl_wrap_socket(sock, keyfile, certfile, cert_reqs, ca_certs, server_hostname, ssl_version, ciphers, ssl_context, ca_cert_dir)
328 if HAS_SNI: # Platform-specific: OpenSSL with enabled SNI
–> 329 return context.wrap_socket(sock, server_hostname=server_hostname)
330

~\anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
447 except OpenSSL.SSL.Error as e:
–> 448 raise ssl.SSLError(‘bad handshake: %r’ % e)
449 break

SSLError: (“bad handshake: Error([(‘SSL routines’, ‘ssl3_get_server_certificate’, ‘certificate verify failed’)],)”,)

During handling of the above exception, another exception occurred:

MaxRetryError Traceback (most recent call last)
~\anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
439 retries=self.max_retries,
–> 440 timeout=timeout
441 )

~\anaconda3\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
638 retries = retries.increment(method, url, error=e, _pool=self,
–> 639 _stacktrace=sys.exc_info()[2])
640 retries.sleep()

~\anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
387 if new_retry.is_exhausted():
–> 388 raise MaxRetryError(_pool, url, error or ResponseError(cause))
389

MaxRetryError: HTTPSConnectionPool(host=‘plot.ly’, port=443): Max retries exceeded with url: /clientresp (Caused by SSLError(SSLError(“bad handshake: Error([(‘SSL routines’, ‘ssl3_get_server_certificate’, ‘certificate verify failed’)],)”,),))

During handling of the above exception, another exception occurred:

SSLError Traceback (most recent call last)
~\anaconda3\lib\site-packages\plotly\api\v1\utils.py in request(method, url, **kwargs)
81 try:
—> 82 response = requests.request(method, url, **kwargs)
83 except RequestException as e:

~\anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
57 with sessions.Session() as session:
—> 58 return session.request(method=method, url=url, **kwargs)
59

~\anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
507 send_kwargs.update(settings)
–> 508 resp = self.send(prep, **send_kwargs)
509

~\anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
617 # Send the request
–> 618 r = adapter.send(request, **kwargs)
619

~\anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
505 # This branch is for urllib3 v1.22 and later.
–> 506 raise SSLError(e, request=request)
507

SSLError: HTTPSConnectionPool(host=‘plot.ly’, port=443): Max retries exceeded with url: /clientresp (Caused by SSLError(SSLError(“bad handshake: Error([(‘SSL routines’, ‘ssl3_get_server_certificate’, ‘certificate verify failed’)],)”,),))

During handling of the above exception, another exception occurred:

PlotlyRequestError Traceback (most recent call last)
in ()
15 data = [trace0, trace1]
16
—> 17 py.plot(data, filename = ‘basic-line’, auto_open=True)

~\anaconda3\lib\site-packages\plotly\plotly\plotly.py in plot(figure_or_data, validate, **plot_options)
240 data = fig.get(‘data’, [])
241 plot_options[‘layout’] = fig.get(‘layout’, {})
–> 242 response = v1.clientresp(data, **plot_options)
243
244 # Check if the url needs a secret key

~\anaconda3\lib\site-packages\plotly\api\v1\clientresp.py in clientresp(data, **kwargs)
33
34 url = ‘{plotly_domain}/clientresp’.format(**cfg)
—> 35 response = request(‘post’, url, data=payload)
36
37 # Old functionality, just keeping it around.

~\anaconda3\lib\site-packages\retrying.py in wrapped_f(*args, **kw)
47 @six.wraps(f)
48 def wrapped_f(*args, **kw):
—> 49 return Retrying(*dargs, **dkw).call(f, *args, **kw)
50
51 return wrapped_f

~\anaconda3\lib\site-packages\retrying.py in call(self, fn, *args, **kwargs)
204
205 if not self.should_reject(attempt):
–> 206 return attempt.get(self._wrap_exception)
207
208 delay_since_first_attempt_ms = int(round(time.time() * 1000)) - start_time

~\anaconda3\lib\site-packages\retrying.py in get(self, wrap_exception)
245 raise RetryError(self)
246 else:
–> 247 six.reraise(self.value[0], self.value[1], self.value[2])
248 else:
249 return self.value

~\anaconda3\lib\site-packages\six.py in reraise(tp, value, tb)
691 if value.traceback is not tb:
692 raise value.with_traceback(tb)
–> 693 raise value
694 finally:
695 value = None

~\anaconda3\lib\site-packages\retrying.py in call(self, fn, *args, **kwargs)
198 while True:
199 try:
–> 200 attempt = Attempt(fn(*args, **kwargs), attempt_number, False)
201 except:
202 tb = sys.exc_info()

~\anaconda3\lib\site-packages\plotly\api\v1\utils.py in request(method, url, **kwargs)
87 status_code = response.status_code if response else None
88 content = response.content if response else ‘No content’
—> 89 raise exceptions.PlotlyRequestError(message, status_code, content)
90 validate_response(response)
91 return response

PlotlyRequestError: No message

Thank you,

Justin

Hi Justin,

I just ran your code in my own Jupyter notebook, and the code itself runs fine. I suspect something is wrong with your api_key. Did you sign up for one when setting up your Plotly account? If so, maybe you have reached your max 25 charts for the month? I know Plotly has a limit on how many charts you can load to your account - if that’s the case, just delete some charts that you no longer need/are older versions. Let me know if that helps.

Hi Jess,

I just signed up yesterday for Plotly, and that was my second graph I tried. I checked my credentials and I copy and pasted from there.

Could it be something that is blocking me from properly loading such as my Anaconda edition or version of plotly I installed via pip?

No matter what I try in Anaconda, I have to install via pip and not the conda install method.

Thanks,

Justin

Hello Justin,
welcome to the Python fold. :man_technologist::metal:

I minor remark. For reasons beyond my limited intelligence, Anaconda install an Anaconda Prompt which is set up with paths to your Python installation and repositories for your installed python packages.
If you open a normal commando prompt and pip install something, I am unsure if it installs in a repository which is recognized by Anaconda.
If you, on the other hand, pip install python packages using your Anaconda Prompt, I am close-to-but-not-100pct sure that it will install to The Good Repository™ where your Anaconda-Python is looking for packages. :slightly_smiling_face:

Hi Blaceus,

Thank you for the help and the warm welcome. I went back in the process and reinstalled Anaconda and made sure I installed Plotly properly. I am still getting one of two error messages.

If I try py.sign_in : PlotlyError: Sign in failed. I have verified that my api key is correct.

If I just use py.tools.set_credentials_file I get the following error: PlotlyRequestError(message, status_code, content)

PlotlyRequestError: No message

Is there a way to ensure I installed “The Good Repository”? Or is there another way to fix this basic issue?

Thanks again for helping a Newbie

Justin

Frankly, I am unable to help you with plotly sign-in problems. I have no experience with this.
An easy way to check if your packages are installed in the Anaconda folder go to the following repository on your computer:
“C:\Users<your user name here>\AppData\Local\Continuum\anaconda3\Lib\site-packages”
And see if you can locate folders with the names of the packages you have installed. :slightly_smiling_face: