none
NEED HELP_ How to authenticate and import data from Excel to Data Catalog Glossary using REST API in Python? RRS feed

  • Question

  • Please let me know from to start? Should an application be created to interact with the REST API? I did  see the .Net example of the same in Microsoft portal, but could not understand much. I mainly want to know whether a native or web application must be created for this in the Azure AD?.  I added a application in the Azure AD for providing authentication tokens, but it does not seem to work and gives 404 errors. 
    Thursday, June 6, 2019 11:00 PM

All replies

  • Hi Sweta92,

    You may refer the SO thread, which addressing similar issue.

    Hope this helps. Do let us know if you any further queries.

    Friday, June 7, 2019 7:27 AM
    Moderator
  • Hi Pradeep,

     I tried to do the below steps:

    authentication_endpoint = 'https://login.microsoftonline.com/'
    resource  = 'https://management.core.windows.net/'
    # get an Azure access token using the adal library
    context = adal.AuthenticationContext(authentication_endpoint + tenant_id)
    resource = "https://login.microsoftonline.com/"
    token_response = context.acquire_token_with_client_credentials(resource, application_id, application_secret)
    access_token = token_response.get('accessToken')

    endpoint = 'https://api.azuredatacatalog.com/catalogs/DefaultCatalog/glossaries/DefaultGlossary/terms?api-version=2016-03-30'

    http_headers = {'Authorization': 'Bearer ' + token_response['accessToken'],
                        'User-Agent': 'adal-python-sample',
                        'Accept': 'application/json',
                        'Content-Type': 'application/json',
                        'client-request-id': str(uuid.uuid4())}

    json_output = requests.get(endpoint,headers=http_headers, stream = False).json()
    print(json_output)

    But I get the below error:

    Error                                     Traceback (most recent call last)
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
        452             try:
    --> 453                 cnx.do_handshake()
        454             except OpenSSL.SSL.WantReadError:
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\OpenSSL\SSL.py in do_handshake(self)
       1914         result = _lib.SSL_do_handshake(self._ssl)
    -> 1915         self._raise_ssl_error(self._ssl, result)
       1916 
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\OpenSSL\SSL.py in _raise_ssl_error(self, ssl, result)
       1646         else:
    -> 1647             _raise_current_error()
       1648 
    
    ~\AppData\Local\Continuum\anaconda3\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\Continuum\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)
        599                                                   body=body, headers=headers,
    --> 600                                                   chunked=chunked)
        601 
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
        342         try:
    --> 343             self._validate_conn(conn)
        344         except (SocketTimeout, BaseSSLError) as e:
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\urllib3\connectionpool.py in _validate_conn(self, conn)
        838         if not getattr(conn, 'sock', None):  # AppEngine might not have  `.sock`
    --> 839             conn.connect()
        840 
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\urllib3\connection.py in connect(self)
        343             server_hostname=server_hostname,
    --> 344             ssl_context=context)
        345 
    
    ~\AppData\Local\Continuum\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)
        343         if HAS_SNI and server_hostname is not None:
    --> 344             return context.wrap_socket(sock, server_hostname=server_hostname)
        345 
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py in wrap_socket(self, sock, server_side, do_handshake_on_connect, suppress_ragged_eofs, server_hostname)
        458             except OpenSSL.SSL.Error as e:
    --> 459                 raise ssl.SSLError('bad handshake: %r' % e)
        460             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\Continuum\anaconda3\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
        448                     retries=self.max_retries,
    --> 449                     timeout=timeout
        450                 )
    
    ~\AppData\Local\Continuum\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)
        637             retries = retries.increment(method, url, error=e, _pool=self,
    --> 638                                         _stacktrace=sys.exc_info()[2])
        639             retries.sleep()
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
        397         if new_retry.is_exhausted():
    --> 398             raise MaxRetryError(_pool, url, error or ResponseError(cause))
        399 
    
    MaxRetryError: HTTPSConnectionPool(host='api.azuredatacatalog.com', port=443): Max retries exceeded with url: /catalogs/DefaultCatalog/glossaries/DefaultGlossary/terms?api-version=2016-03-30 (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)
    <ipython-input-4-0d9c4e545809> in <module>
          1 
    ----> 2 json_output = requests.get(endpoint,headers=http_headers, stream = False).json()
          3 print(json_output)
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
         73 
         74     kwargs.setdefault('allow_redirects', True)
    ---> 75     return request('get', url, params=params, **kwargs)
         76 
         77 
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
         58     # cases, and look like a memory leak in others.
         59     with sessions.Session() as session:
    ---> 60         return session.request(method=method, url=url, **kwargs)
         61 
         62 
    
    ~\AppData\Local\Continuum\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)
        531         }
        532         send_kwargs.update(settings)
    --> 533         resp = self.send(prep, **send_kwargs)
        534 
        535         return resp
    
    ~\AppData\Local\Continuum\anaconda3\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
        644 
        645         # Send the request
    --> 646         r = adapter.send(request, **kwargs)
        647 
        648         # Total elapsed time of the request (approximately)
    
    ~\AppData\Local\Continuum\anaconda3\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='api.azuredatacatalog.com', port=443): Max retries exceeded with url: /catalogs/DefaultCatalog/glossaries/DefaultGlossary/terms?api-version=2016-03-30 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])"))
    

    Could please help me on this regard? Should a certificate be uploaded to the Active AD application?

     

    Friday, June 7, 2019 9:37 PM
  • Hi Sweta92,

    It’s an issue you will have to resolve by whitelisting the CA certificate used to sign the remote server certificate you are trying to connect to from your system settings. But for the purposes of testing out only, you can turn off the verification using:

    output = requests.get('url, verify=False)

    For more details, refer SO thread, which address similar issue.

    Hope this helps. Do let us know if you any further queries.

    Monday, June 10, 2019 10:04 AM
    Moderator
  • Hi Pradeep,

      Could please mention what is the authentication_endpoint and resource for the data catalog API in python?

    Tuesday, June 11, 2019 8:19 PM