cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Error while installing SAT tool in azure databricks

p-kolluri
New Contributor II

Hi, was running the security analysis initializer notebook, am I'm getting an error in cmd 8 for import_dashboard_template notebook. That is notebook no.5. First got an error for cmd 8  for this line "workspacedf = spark.sql("select * from `global_temp`.`all_workspaces` where workspace_id='" + current_workspace + "'" )" . After changing the line to "workspacedf = dfexist.filter(dfexist['workspace_id'] == current_workspace)" the cell worked fine. But now getting an error in cmd 9 for this line "
if resource['endpoint_id'] == json_['sql_warehouse_id']:. "as string indices must be integers". Can someone help me with this. Thank you.

@arun_pamulapati 

3 REPLIES 3

Kaniz
Community Manager
Community Manager

Hi @p-kolluriThe error message "string indices must be integers" typically occurs when using a string as an index for a list or a dictionary in Python. In your case, it seems like resource or json_ might not be the type of object you're expecting it to be.

The line of code if resource['endpoint_id'] == json_['sql_warehouse_id']: suggests that both resource and json_ are expected to be dictionaries with keys 'endpoint_id' and 'sql_warehouse_id' respectively.

You should check the type and content of resource and json_ before this line of code is executed.

p-kolluri
New Contributor II

 Also here is the whole code 

import requests
DOMAIN = ws.deployment_url
TOKEN =  dbutils.secrets.get(json_['workspace_pat_scope'], ws.ws_token)
print(json_['workspace_pat_scope'])
loggr.info(f"Looking for data_source_id for : {json_['sql_warehouse_id']}!")
response = requests.get(
          'https://%s/api/2.0/preview/sql/data_sources' % (DOMAIN),
          headers={'Authorization': 'Bearer %s' % TOKEN},
          json=None,
          timeout=60
        )

print(response)
resources = json.loads(response.text)

found = False
for resource in resources:
    if resource['endpoint_id'] == json_['sql_warehouse_id']:
        data_source_id = resource['id']
        loggr.info(f"Found data_source_id for : {json_['sql_warehouse_id']}!")
        found = True
        break
           
if (found == False๐Ÿ˜ž
    dbutils.notebook.exit("The configured SQL Warehouse Endpoint is not found.")
 
And when trying to run this code 
import requests
DOMAIN = ws.deployment_url
TOKEN =  dbutils.secrets.get(json_['workspace_pat_scope'], ws.ws_token)
print(json_['workspace_pat_scope'])
loggr.info(f"Looking for data_source_id for : {json_['sql_warehouse_id']}!")
response = requests.get(
          'https://%s/api/2.0/preview/sql/data_sources' % (DOMAIN),
          headers={'Authorization': 'Bearer %s' % TOKEN},
          json=None,
          timeout=60
        )

print(response)
Getting a 403 error. That might be the problem. The token and api pair work ok when we tried to get a response in CLI not sure why its not working in databricks.
 

victormarcel09
New Contributor II

Hii,

You can double-check the structure and contents of the json_ object to ensure it contains the expected keys and values. If you still encounter issues, verify the data types and perform necessary type conversions to ensure compatibility.

Best regard,
Follow My Health
Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.