1

以下代码在计算实例中的 jupyter notebook 上运行良好。但是我需要在 Visual Studio Code 上进行本地测试

import pandas as pd
import datetime
import csv
import numpy as np
from azureml.core import Workspace
from azureml.core import Dataset, Datastore
from azureml.data.datapath import DataPath
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
from azureml.core.authentication import AzureCliAuthentication

# #azure-cosmosdb-table
# from azure.cosmosdb.table.tableservice import TableService
# from azure.cosmosdb.table.models import Entity

#Azure blob storage

cli_auth = AzureCliAuthentication()

ws = Workspace(subscription_id="xx",
               resource_group="xx",
               workspace_name="xx",
               auth=cli_auth)

print("Found workspace {} at location {}".format(ws.name, ws.location))


import os
from azureml.core.authentication import ServicePrincipalAuthentication

svc_pr_password = "xx" #os.environ.get("AZUREML_PASSWORD")

svc_pr = ServicePrincipalAuthentication(
    tenant_id="xx",
    service_principal_id="xx",
    service_principal_password=svc_pr_password)


ws = Workspace(
    subscription_id="xx",
    resource_group="xx",
    workspace_name="xx",
    auth=svc_pr
    )

print("Found workspace {} at location {}".format(ws.name, ws.location))

但是这一行:

  datastore = Datastore.get(ws, 'yy')

给我这个错误:

---------------------------------------------------------------------------
Error                                     Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
    487             try:
--> 488                 cnx.do_handshake()
    489             except OpenSSL.SSL.WantReadError:

~\AppData\Local\Programs\Python\Python38\lib\site-packages\OpenSSL\SSL.py in do_handshake(self)
   1933         result = _lib.SSL_do_handshake(self._ssl)
-> 1934         self._raise_ssl_error(self._ssl, result)
   1935 

~\AppData\Local\Programs\Python\Python38\lib\site-packages\OpenSSL\SSL.py in _raise_ssl_error(self, ssl, result)
   1670         else:
-> 1671             _raise_current_error()
   1672 

~\AppData\Local\Programs\Python\Python38\lib\site-packages\OpenSSL\_util.py in exception_from_error_queue(exception_type)
     53 
---> 54     raise exception_type(errors)
     55 

Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

SSLError                                  Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python38\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)
    669             # Make the request on the httplib connection object.
--> 670             httplib_response = self._make_request(
    671                 conn,

~\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    380         try:
--> 381             self._validate_conn(conn)
    382         except (SocketTimeout, BaseSSLError) as e:

~\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connectionpool.py in _validate_conn(self, conn)
    975         if not getattr(conn, "sock", None):  # AppEngine might not have  `.sock`
--> 976             conn.connect()
    977 

~\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\connection.py in connect(self)
    360 
--> 361         self.sock = ssl_wrap_socket(
    362             sock=conn,

~\AppData\Local\Programs\Python\Python38\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, key_password, ca_cert_data)
    376         if HAS_SNI and server_hostname is not None:
--> 377             return context.wrap_socket(sock, server_hostname=server_hostname)
    378 

~\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
    493             except OpenSSL.SSL.Error as e:
--> 494                 raise ssl.SSLError("bad handshake: %r" % e)
    495             break

SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
~\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    438             if not chunked:
--> 439                 resp = conn.urlopen(
    440                     method=request.method,

~\AppData\Local\Programs\Python\Python38\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)
    723 
--> 724             retries = retries.increment(
    725                 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]

~\AppData\Local\Programs\Python\Python38\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    438         if new_retry.is_exhausted():
--> 439             raise MaxRetryError(_pool, url, error or ResponseError(cause))
    440 

MaxRetryError: HTTPSConnectionPool(host='westeurope.experiments.azureml.net', port=443): Max retries exceeded with url: /discovery (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:

SSLError                                  Traceback (most recent call last)
 in 
----> 1 datastore = Datastore.get(ws, 'utilisationdb')

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\core\datastore.py in get(workspace, datastore_name)
    139                 or azureml.data.dbfs_datastore.DBFSDatastore
    140         """
--> 141         return Datastore._client().get(workspace, datastore_name)
    142 
    143     @staticmethod

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\data\datastore_client.py in get(workspace, datastore_name)
     63         :rtype: AzureFileDatastore or AzureBlobDatastore
     64         """
---> 65         return _DatastoreClient._get(workspace, datastore_name)
     66 
     67     @staticmethod

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\data\datastore_client.py in _get(ws, name, auth, host)
    541         module_logger.debug("Getting datastore: {}".format(name))
    542 
--> 543         client = _DatastoreClient._get_client(ws, auth, host)
    544         datastore = client.data_stores.get(subscription_id=ws._subscription_id, resource_group_name=ws._resource_group,
    545                                            workspace_name=ws._workspace_name, name=name,

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\data\datastore_client.py in _get_client(ws, auth, host)
    726         host_env = os.environ.get('AZUREML_SERVICE_ENDPOINT')
    727         auth = auth or ws._auth
--> 728         host = host or host_env or get_service_url(
    729             auth, _DatastoreClient._get_workspace_uri_path(ws._subscription_id, ws._resource_group,
    730                                                            ws._workspace_name), ws._workspace_id, ws.discovery_url)

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_base_sdk_common\service_discovery.py in get_service_url(auth, workspace_scope, workspace_id, workspace_discovery_url, service_name)
    118 
    119     cached_service_object = CachedServiceDiscovery(auth)
--> 120     return cached_service_object.get_cached_service_url(workspace_scope, service_name,
    121                                                         unique_id=workspace_id, discovery_url=workspace_discovery_url)
    122 

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_base_sdk_common\service_discovery.py in get_cached_service_url(self, arm_scope, service_name, unique_id, discovery_url)
    280         :rtype: str
    281         """
--> 282         return self.get_cached_services_uris(arm_scope, service_name, unique_id=unique_id,
    283                                              discovery_url=discovery_url)[service_name]

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_base_sdk_common\service_discovery.py in wrapper(self, *args, **kwargs)
    180             try:
    181                 lock_to_use.acquire()
--> 182                 return test_function(self, *args, **kwargs)
    183             finally:
    184                 lock_to_use.release()

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_base_sdk_common\service_discovery.py in get_cached_services_uris(self, arm_scope, service_name, unique_id, discovery_url)
    255 
    256         # Actual service discovery only understands arm_scope
--> 257         cache[cache_key][DEFAULT_FLIGHT] = super(CachedServiceDiscovery, self).discover_services_uris_from_arm_scope(arm_scope, discovery_url)
    258         try:
    259             with open(self.file_path, "w+") as file:

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_base_sdk_common\service_discovery.py in discover_services_uris_from_arm_scope(self, arm_scope, discovery_url)
    136     def discover_services_uris_from_arm_scope(self, arm_scope, discovery_url=None):
    137         discovery_url = self.get_discovery_url(arm_scope, discovery_url)
--> 138         return self.discover_services_uris(discovery_url)
    139 
    140     def discover_services_uris(self, discovery_url=None):

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_base_sdk_common\service_discovery.py in discover_services_uris(self, discovery_url)
    139 
    140     def discover_services_uris(self, discovery_url=None):
--> 141         status = ClientBase._execute_func(requests.get, discovery_url)
    142         status.raise_for_status()
    143         return status.json()

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_restclient\clientbase.py in _execute_func(cls, func, *args, **kwargs)
    340     @classmethod
    341     def _execute_func(cls, func, *args, **kwargs):
--> 342         return cls._execute_func_internal(
    343             DEFAULT_BACKOFF, DEFAULT_RETRIES, module_logger, func, _noop_reset, *args, **kwargs)
    344 

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_restclient\clientbase.py in _execute_func_internal(cls, back_off, total_retry, logger, func, reset_func, *args, **kwargs)
    334                 return func(*args, **kwargs)
    335             except Exception as error:
--> 336                 left_retry = cls._handle_retry(back_off, left_retry, total_retry, error, logger, func)
    337 
    338             reset_func(*args, **kwargs)  # reset_func is expected to undo any side effects from a failed func call.

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_restclient\clientbase.py in _handle_retry(cls, back_off, left_retry, total_retry, error, logger, func)
    364         """
    365         if left_retry == 0:
--> 366             raise error
    367         elif isinstance(error, HttpOperationError):
    368             if error.response.status_code == 403:

~\AppData\Local\Programs\Python\Python38\lib\site-packages\azureml\_restclient\clientbase.py in _execute_func_internal(cls, back_off, total_retry, logger, func, reset_func, *args, **kwargs)
    332         while left_retry >= 0:
    333             try:
--> 334                 return func(*args, **kwargs)
    335             except Exception as error:
    336                 left_retry = cls._handle_retry(back_off, left_retry, total_retry, error, logger, func)

~\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py in get(url, params, **kwargs)
     74 
     75     kwargs.setdefault('allow_redirects', True)
---> 76     return request('get', url, params=params, **kwargs)
     77 
     78 

~\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\api.py in request(method, url, **kwargs)
     59     # cases, and look like a memory leak in others.
     60     with sessions.Session() as session:
---> 61         return session.request(method=method, url=url, **kwargs)
     62 
     63 

~\AppData\Local\Programs\Python\Python38\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)
    528         }
    529         send_kwargs.update(settings)
--> 530         resp = self.send(prep, **send_kwargs)
    531 
    532         return resp

~\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
    641 
    642         # Send the request
--> 643         r = adapter.send(request, **kwargs)
    644 
    645         # Total elapsed time of the request (approximately)

~\AppData\Local\Programs\Python\Python38\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    512             if isinstance(e.reason, _SSLError):
    513                 # This branch is for urllib3 v1.22 and later.
--> 514                 raise SSLError(e, request=request)
    515 
    516             raise ConnectionError(e, request=request)

SSLError: HTTPSConnectionPool(host='westeurope.experiments.azureml.net', port=443): Max retries exceeded with url: /discovery (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
4

0 回答 0