<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Access Databricks Table with Simple Python3 Script in Get Started Discussions</title>
    <link>https://community.databricks.com/t5/get-started-discussions/access-databricks-table-with-simple-python3-script/m-p/94946#M4459</link>
    <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/8379"&gt;@gchandra&lt;/a&gt;&amp;nbsp;Yes!&amp;nbsp; This is the documentation I was seeking!&amp;nbsp; Thank you so much&lt;/P&gt;</description>
    <pubDate>Fri, 18 Oct 2024 19:51:47 GMT</pubDate>
    <dc:creator>redapplesonly</dc:creator>
    <dc:date>2024-10-18T19:51:47Z</dc:date>
    <item>
      <title>Access Databricks Table with Simple Python3 Script</title>
      <link>https://community.databricks.com/t5/get-started-discussions/access-databricks-table-with-simple-python3-script/m-p/94638#M4440</link>
      <description>&lt;P&gt;Hi, I'm super new to Databricks. I'm trying to do a little API scripting against my company's DB instance.&lt;BR /&gt;I have this supersimple python (ver 3) which is meant to run a remote host.&amp;nbsp; The script tries to a simple SQL query against my Databricks instance:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import requests
import json

HOST = 'https://**********************************'
TOKEN = '**************************'
endpoint = f'{HOST}/api/2.0/sql/queries'

headers = {
    'Authorization': f'Bearer {TOKEN}',
    'Content-Type': 'application/json'
}

data = {
    "query": "SELECT * FROM table1 LIMIT 10",
    "data_source": {
        "catalog_name": "hive_metastore",
        "schema_name": "default"
    },
    "output_format": "json"
}

response = requests.post(endpoint, headers=headers, data=json.dumps(data))

if response.status_code == 200:
    query_result = response.json()
    print("Query executed successfully. Results:")
    print(query_result)
else:
    print(f"Failed to execute query. Status code: {response.status_code}, Message: {response.text}")&lt;/LI-CODE&gt;&lt;P&gt;What could be simpler? "Give me the first ten rows of 'table1'."&lt;BR /&gt;(I have verified that the URL and token are valid.)&lt;BR /&gt;The problem is that when I run the program, Databricks doesn't like the formatting of the `data` JSON dictionary. Here's the error I see when the script runs:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Failed to execute query. Status code: 400, Message: {"error_code":"MALFORMED_REQUEST","message":"Could not parse request object: Expected 'START_OBJECT' not 'VALUE_STRING'\n at [Source: (ByteArrayInputStream); line: 1, column: 11]\n at [Source: java.io.ByteArrayInputStream@1cb8bdf; line: 1, column: 11]"}&lt;/LI-CODE&gt;&lt;P&gt;I don't really understand what this error message means, but the AI chatbot I'm using assures me that Databricks is gagging on the format of my JSON `data` payload. "&lt;EM&gt;&lt;STRONG&gt;Consult the Databricks documentation&lt;/STRONG&gt;&lt;/EM&gt;" is its best advice.&lt;/P&gt;&lt;P&gt;So I guess I was hoping for some general advice. Is my approach naive? If so, could someone recommend an example program I could consult? thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2024 19:38:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/access-databricks-table-with-simple-python3-script/m-p/94638#M4440</guid>
      <dc:creator>redapplesonly</dc:creator>
      <dc:date>2024-10-17T19:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Access Databricks Table with Simple Python3 Script</title>
      <link>https://community.databricks.com/t5/get-started-discussions/access-databricks-table-with-simple-python3-script/m-p/94680#M4445</link>
      <description>&lt;P&gt;The request sample looks different.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://docs.databricks.com/api/workspace/queries/create" target="_blank"&gt;https://docs.databricks.com/api/workspace/queries/create&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 02:19:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/access-databricks-table-with-simple-python3-script/m-p/94680#M4445</guid>
      <dc:creator>gchandra</dc:creator>
      <dc:date>2024-10-18T02:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Access Databricks Table with Simple Python3 Script</title>
      <link>https://community.databricks.com/t5/get-started-discussions/access-databricks-table-with-simple-python3-script/m-p/94946#M4459</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/8379"&gt;@gchandra&lt;/a&gt;&amp;nbsp;Yes!&amp;nbsp; This is the documentation I was seeking!&amp;nbsp; Thank you so much&lt;/P&gt;</description>
      <pubDate>Fri, 18 Oct 2024 19:51:47 GMT</pubDate>
      <guid>https://community.databricks.com/t5/get-started-discussions/access-databricks-table-with-simple-python3-script/m-p/94946#M4459</guid>
      <dc:creator>redapplesonly</dc:creator>
      <dc:date>2024-10-18T19:51:47Z</dc:date>
    </item>
  </channel>
</rss>

