databricks cli: getting b'Bad request error

Viewed 3391

I am trying to use Databricks CLI for the first time. Whenever I try something using cli it gives me the message: "Error: b'Bad Request'"
This is same for any cli based command
I am able to do authenticate (Tried with a wrong token and got the authentication error)
Please find the debug trace for the same below:
command: databricks fs ls --debug

result:
HTTP debugging enabled
send: b'GET /api/2.0/dbfs/list?path=dbfs%3A%2F HTTP/1.1\r\nHost: xxx-xxxxxxxxxxxxxxxx.xx.azuredatabricks.net\r\nuser-agent: databricks-cli-0.14.0-fs-ls-a2695361-282f-11eb-83c1-34f39aa616fb\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nAuthorization: Bearer \x16\r\nContent-Type: text/json\r\n\r\n'
reply: 'HTTP/1.1 400 Bad Request\r\n'
header: content-length: 11
header: content-type: text/plain<br>
header: date: Mon, 16 Nov 2020 17:17:42 GMT
header: server: databricks
header: connection: close
Error: b'Bad Request'
2 Answers
  • Go to c:/users/youruser/.databrickscfg
  • Open above file in notepad
  • verify that URL and token are correct

Most likely token is not stored in the correct format. Thanks.

Before you can run CLI commands, you must set up authentication. To authenticate to the CLI you can use a Databricks personal access token or an Azure Active Directory (Azure AD) token.

Steps for installing and configuring Azure Databricks CLI using cmd:

Step1: Install Python, you’ll need Python version 2.7.9 and above if you’re using Python 2 or Python 3.6 and above if you’re using Python 3.

Step2: Run pip install databricks-cli using the appropriate version of pip for your Python installation. If you are using Python 3, run pip3 install databricks-cli.

Step3: Setup authentication => To authenticate and access Databricks REST APIs, you use personal access tokens. Tokens are similar to passwords; you should treat them with care. Tokens expire and can be revoked.

  • Click the user profile icon User Profile in the upper right corner of your Azure Databricks workspace.

  • Click User Settings.

  • Go to the Access Tokens tab.

enter image description here

  • Click the Generate New Token button.
  • Optionally enter a description (comment) and expiration period.

enter image description here

  • Click the Generate button.
  • Make sure to "Copy" the generated token and store in a secure location.

Step4: Copy the URL of databricks host "https://centralus.azuredatabricks.net/" and token which created earlier step.

Step5: In cmd run "dbfs configure --token" as shown below:

dbfs configure --token
Databricks Host (should begin with https://): https://centralus.azuredatabricks.net
Token: dapi72026dsfsdfsh987hjfiu431

Step6: Successfully configured Databricks CLI using CMD.

To verify try to run "databricks fs ls", check whether you are able to see the DBFS.

enter image description here

Reference: Databricks CLI

Related