Pop-up Message Box in Power BI Using Python

Photo by David Clode on Unsplash

Pop-up Message Box in Power BI Using Python

I had a requirement to show a pop up in Power BI. Did some googling and found this:

I was following through the steps and ended up with this error here:

ADO.NET: Python script error.

Getting the above, even though I can see that i already have numpy installed

Did some more digging around and found from this community article below that Power BI does not support Python 3.7. However, I cannot find official documentation from Microsoft that states this. https://community.powerbi.com/t5/Desktop/Error-when-connecting-python-to-PBI/m-p/594361#M282204

So then i attempt to install 3.6 conda create -n py36 python=3.6 anaconda -v and ran into the more errors below:

WARNING: The conda.compat module is deprecated and will be removed in a future release.
Collecting package metadata: ...working... Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])"))': /pkgs/r/noarch/repodata.json.bz2Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])"))': /pkgs/r/noarch/repodata.json.bz2Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])"))': /pkgs/r/noarch/repodata.json.bz2failed
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 453, in wrap_socket
    cnx.do_handshake()
  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1915, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\SSL.py", line 1647, in _raise_ssl_error
    _raise_current_error()
  File "C:\ProgramData\Anaconda3\lib\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]During handling of the above exception, another exception occurred:Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 839, in _validate_conn
    conn.connect()
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connection.py", line 344, in connect
    ssl_context=context)
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\ssl_.py", line 344, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 459, in wrap_socket
    raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)During handling of the above exception, another exception occurred:Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
    **response_kw)
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
    **response_kw)
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
    **response_kw)
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\ProgramData\Anaconda3\lib\site-packages\urllib3\util\retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/r/noarch/repodata.json.bz2 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))During handling of the above exception, another exception occurred:Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 429, in fetch_repodata_remote_request
    timeout=timeout)
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 546, in get
    return self.request('GET', url, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/r/noarch/repodata.json.bz2 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))During handling of the above exception, another exception occurred:Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\exceptions.py", line 1003, in __call__
    return func(*args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\main.py", line 84, in _main
    exit_code = do_call(args, p)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\conda_argparse.py", line 82, in do_call
    exit_code = getattr(module, func_name)(args, parser)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\main_create.py", line 37, in execute
    install(args, parser, 'create')
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\cli\install.py", line 257, in install
    force_reinstall=context.force_reinstall or context.force,
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\solve.py", line 107, in solve_for_transaction
    force_remove, force_reinstall)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\solve.py", line 145, in solve_for_diff
    force_remove)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\solve.py", line 235, in solve_final_state
    ssc = self._collect_all_metadata(ssc)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\common\io.py", line 88, in decorated
    return f(*args, **kwds)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\solve.py", line 286, in _collect_all_metadata
    index, r = self._prepare(prepared_specs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\solve.py", line 688, in _prepare
    self.subdirs, prepared_specs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\index.py", line 213, in get_reduced_index
    new_records = query_all(spec)
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\index.py", line 176, in query_all
    return tuple(concat(future.result() for future in as_completed(futures)))
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 93, in query
    self.load()
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 147, in load
    _internal_state = self._load()
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 218, in _load
    mod_etag_headers.get('_mod'))
  File "C:\ProgramData\Anaconda3\lib\site-packages\conda\core\subdir_data.py", line 535, in fetch_repodata_remote_request
    caused_by=e)
conda.exceptions.CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com/pkgs/r/noarch/repodata.json.bz2>
Elapsed: -An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.If your current network has https://www.anaconda.com blocked, please file
a support request with your network engineering team.SSLError(MaxRetryError('HTTPSConnectionPool(host=\'repo.anaconda.com\', port=443): Max retries exceeded with url: /pkgs/r/noarch/repodata.json.bz2 (Caused by SSLError(SSLError("bad handshake: Error([(\'SSL routines\', \'tls_process_server_certificate\', \'certificate verify failed\')])")))'))

Looks to be an SSL error, since i don’t have a cert available, i needed to disable the ssl check conda config — set ssl_verify false then i was finally able to install Python 3.6conda create n -py36 python=3.6 anaconda -v

After Python 3.6 finished installing, we then go back to Power BI to point to the new environment.

we then install the required pywin32 package into the newly created py36 environment.

(py36) PS C:\WINDOWS\system32> conda install pywin32 -v
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working...
The environment is inconsistent, please check the package plan carefully
The following packages are causing the inconsistency:- defaults/win-64::anaconda==2019.07=py36_0
  - defaults/win-64::numba==0.45.0=py36hf9181ef_0
done
initializing UnlinkLinkTransaction with
  target_prefix: C:\ProgramData\Anaconda3\envs\py36
  unlink_precs:
    defaults::anaconda-2019.07-py36_0
    defaults::certifi-2019.6.16-py36_0
    defaults::ca-certificates-2019.5.15-0
  link_precs:
    defaults::ca-certificates-2019.5.15-1
    defaults::tbb-2019.4-h74a9793_0
    defaults::certifi-2019.6.16-py36_1
    defaults::anaconda-custom-py36_1
    defaults::_anaconda_depends-2019.03-py36_0## Package Plan ##environment location: C:\ProgramData\Anaconda3\envs\py36added / updated specs:
    - pywin32The following packages will be downloaded:package                    |            build
    ---------------------------|-----------------
    _anaconda_depends-2019.03  |           py36_0           5 KB
    anaconda-custom            |           py36_1           2 KB
    ca-certificates-2019.5.15  |                1         166 KB
    certifi-2019.6.16          |           py36_1         156 KB
    tbb-2019.4                 |       h74a9793_0         173 KB
    ------------------------------------------------------------
                                           Total:         503 KBThe following NEW packages will be INSTALLED:_anaconda_depends  pkgs/main/win-64::_anaconda_depends-2019.03-py36_0
  tbb                pkgs/main/win-64::tbb-2019.4-h74a9793_0The following packages will be UPDATED:ca-certificates                               2019.5.15-0 --> 2019.5.15-1
  certifi                                  2019.6.16-py36_0 --> 2019.6.16-py36_1The following packages will be DOWNGRADED:anaconda                                   2019.07-py36_0 --> custom-py36_1Proceed ([y]/n)? yPreparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... ===> UNLINKING PACKAGE: defaults::anaconda-2019.07-py36_0 <===
  prefix=C:\ProgramData\Anaconda3\envs\py36===> UNLINKING PACKAGE: defaults::certifi-2019.6.16-py36_0 <===
  prefix=C:\ProgramData\Anaconda3\envs\py36===> UNLINKING PACKAGE: defaults::ca-certificates-2019.5.15-0 <===
  prefix=C:\ProgramData\Anaconda3\envs\py36===> LINKING PACKAGE: defaults::ca-certificates-2019.5.15-1 <===
  prefix=C:\ProgramData\Anaconda3\envs\py36
  source=C:\ProgramData\Anaconda3\pkgs\ca-certificates-2019.5.15-1===> LINKING PACKAGE: defaults::tbb-2019.4-h74a9793_0 <===
  prefix=C:\ProgramData\Anaconda3\envs\py36
  source=C:\ProgramData\Anaconda3\pkgs\tbb-2019.4-h74a9793_0===> LINKING PACKAGE: defaults::certifi-2019.6.16-py36_1 <===
  prefix=C:\ProgramData\Anaconda3\envs\py36
  source=C:\ProgramData\Anaconda3\pkgs\certifi-2019.6.16-py36_1===> LINKING PACKAGE: defaults::anaconda-custom-py36_1 <===
  prefix=C:\ProgramData\Anaconda3\envs\py36
  source=C:\ProgramData\Anaconda3\pkgs\anaconda-custom-py36_1===> LINKING PACKAGE: defaults::_anaconda_depends-2019.03-py36_0 <===
  prefix=C:\ProgramData\Anaconda3\envs\py36
  source=C:\ProgramData\Anaconda3\pkgs\_anaconda_depends-2019.03-py36_0done

After the remediation steps above, i was able to follow through and add the pop-up message 😎!

Did you find this article valuable?

Support Ian's blog by becoming a sponsor. Any amount is appreciated!