我目前正在尝试连接到azuredatalakes-gen2,使用python从存储在里面的json文件中获取信息。听说用于python的azuredatalakes模块不适用于gen2(我自己也有问题),我接着通过restapi和python中的requests包进行连接。然而,阅读微软留下的参考资料和所需的身份验证标头让我更加困惑该怎么做。在
虽然我对python有一个大致的了解,但在更高级的项目上我还是个业余爱好者,而且总是需要查资料,但是这是我第一次问问题寻求帮助,而不是搜索,直到找到答案(所以请耐心等待)。在
我发现michalpawlikowski提供了一个有用的链接,解释了如何通过powershell进行连接,这有助于解释许多松散的结尾,但仍然存在两个问题,第一,我不确定如何正确编码身份验证头。特别是“通过在UTF-8编码的签名字符串上使用HMAC-SHA256算法对这个字符串进行编码”,第二个原因是这将只列出目录中找到的文件,而不是文件中包含的信息。在
这是我试过的
date = "Wed, 15 May 2019 14:28:01 GMT"
string_to_sign = 'GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:'+date+'\nx-ms-version:2018-11-09\n/'+STORAGE_ACCOUNT_NAME+'/'+FILE_SYSTEM_NAME+'\nrecursive:true\nresource:fileststem'
signature = #Encoded string_to_sign + key, am unsure how to approach
auth_header = "SharedKey "+STORAGE_ACCOUNT_NAME+":"+signature
headers = {"Authorization" : auth_header, "x-ms-version" : "2018-11-09", "x-ms-date" : date}
req = requests.get("https://"+STORAGE_ACCOUNT_NAME+".dfs.core.windows.net/" + FILE_SYSTEM_NAME + "?recursive=true&resource=filesystem", headers=headers)
我希望如此需求文本为了包含json文件中的信息,我总是会收到一个403错误,声明要确保我的头格式正确。在
如果要读取文件内容,应使用Read api。在
以下代码适用于我:
试验结果:
相关问题 更多 >
编程相关推荐