简体   繁体   English

获取 HTTP 错误 403 - 尝试通过 Azure 数据块访问集群时访问令牌无效

[英]Getting HTTP error 403 - invalid access token while trying to access cluster through Azure databricks

I'm trying to access Azure databricks spark cluster by a python script which takes token as an input generated via databricks user settings and calling a Get method to get the details of the cluster alongwith the cluster-id.我正在尝试通过 python 脚本访问 Azure databricks spark 集群,该脚本将令牌作为通过 databricks 用户设置生成的输入,并调用 Get 方法来获取集群的详细信息以及集群 ID。

The below is the code snippet.下面是代码片段。 As shown, I have created a cluster in southcentralus zone.如图所示,我在中南区创建了一个集群。

import requests
headers = {"Authorization":"Bearer dapiad************************"}
data=requests.get("https://southcentralus.azuredatabricks.net/api/2.0/clusters/get?cluster_id=**************",headers=headers).text
print data

Expected result should give the full detail of the cluster eg.预期结果应该给出集群的全部细节,例如。 {"cluster_id":"0128-******","spark_context_id":3850138716505089853,"cluster_name":"abcdxyz","spark_version":"5.1.x-scala2.11","spark_conf":{"spark.databricks.delta.preview.enabled":"true"},"node_type_id" and so on .....}

The above code is working when I execute the code on google colaboratory whereas the same is not working with my local IDE ie idle.当我在 google colaboratory 上执行代码时,上面的代码正在工作,而我的本地 IDE 即空闲时同样不能工作。 It gives the error of HTTP 403 stating as below:它给出了 HTTP 403 的错误,如下所示:

<p>Problem accessing /api/2.0/clusters/get. Reason:
<pre>    Invalid access token.</pre></p>

Can anyone help me resolve the issue?谁能帮我解决这个问题? I'm stuck on this part and not able to access the cluster through APIs.我被困在这部分,无法通过 API 访问集群。

It could be due to encoding issue when you pass the secret.这可能是由于您传递秘密时的编码问题。 Please look into this issue and how to resolve it.请查看此问题以及如何解决它。 Even though the resolution they have given for AWS,it could be similar one for Azure as well.尽管他们为 AWS 提供了解决方案,但它也可能与 Azure 类似。 Your secret might be having "/", which you have to replace.您的秘密可能有“/”,您必须替换它。

There is a known problem in the last update related to the '+' character in secret keys.上次更新中存在与密钥中的“+”字符相关的已知问题。 In particular, we no longer support escaping '+' into '%2B', which some URL-encoding libraries do.特别是,我们不再支持将“+”转义为“%2B”,某些 URL 编码库会这样做。

The current best-practice way of encoding your AWS secret key is simply当前编码 AWS 密钥的最佳实践方法很简单

secretKey.replace("/","%2F")

sample python script is given below:示例 python 脚本如下:

New_Secret_key = "MySecret/".replace("/","%2F")

https://forums.databricks.com/questions/6590/s3serviceexception-raised-when-accessing-via-mount.html https://forums.databricks.com/questions/6590/s3serviceexception-raised-when-accessing-via-mount.html

https://forums.databricks.com/questions/6621/responsecode403-responsemessageforbidden.html https://forums.databricks.com/questions/6621/responsecode403-responsemessageforbidden.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用 python 访问 API 时出现无效令牌错误 - Invalid token error while trying to access an API using python 在尝试撤销 OAuth2 访问令牌(Google 登录)时获取 invalid_token 和令牌过期或撤销 - Getting invalid_token & Token expired or revoked while trying to revoke OAuth2 access token (Google Sign in) 尝试访问 Google 表格时出现“无访问令牌响应”错误 - "No access token in response" error, while trying to access to Google Sheet 通过OAuth 2.0获取访问令牌时出现invalid_grant错误 - invalid_grant error while getting access token via OAuth 2.0 尝试访问 Azure Databricks 中的 Azure DBFS 文件系统时出现挂载错误 - mount error when trying to access the Azure DBFS file system in Azure Databricks 尝试访问Twitter API时出现“无效或过期的令牌”错误 - “Invalid or expired token” error when trying to access Twitter API 从 Azure Function 获取托管身份访问令牌时出错 - Error Getting Managed Identity Access Token from Azure Function 创建范围以从 Databricks 访问 Azure Datalake Gen2 时出现属性错误 - Attribute error while creating scope to access Azure Datalake Gen2 from Databricks 尝试获取Twitter授权的访问密钥时出现401错误 - Getting 401 error while trying to get access key for Twitter authorization 尝试使用 boto3 访问 s3 存储桶,但得到 403 - Trying to access a s3 bucket using boto3, but getting 403
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM