0

I am using Databricks Rest API to read datasets stored on DFBS. The output is coming in 64bit encoded format and in json format. I need the output in tabular format which is easy to read.

Output of Rest Api: { "bytes_read": 4601, "data": "U2VwYWxMZW5ndGgsU2VwYWxXaWR0aCxQZXRhbE" }

output needed:

enter image description here

3
  • Are you sure there's no more output? Running that data value through a Base64 decoder gives part of the column names from your image, so it seems like there should be more information in the response. Commented Jul 25, 2020 at 7:40
  • The output was a bigger string. I shortened it for the sake of simplicity. I there a way to decode it and get a table structure in the in the API Itself. Commented Jul 25, 2020 at 8:19
  • Not sure. I'd guess is you base64 decoded the full string, you'd get the table in CSV form. Can't tell without the full string though. Commented Jul 26, 2020 at 16:58

1 Answer 1

1

You can use below code to download csv file,

jsonbody = {"path": dbfspath}

TOKEN = "dapi....." # you can generate this token from users settings

response = requests.get('https://eastus.azuredatabricks.net/api/2.0/dbfs/read/', headers={'Authorization': 'Bearer %s' % self.TOKEN }, json= jsonbody )

filedata = json.loads(response.text)["data"]

with open(outputpath, "wb") as file:

  file.write(base64.b64decode(filedata))

Let me know if you need any other help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.