[英]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.