繁体   English   中英

Json to excel from devops to storage account with help of azure function in python

[英]Json to excel from devops to storage account with help of azure function in python

devops 存储库中有一个 .json 文件。 What we need to do is to make an azure function which will take the.json file from azure devops repository, then convert it into excel, and at last saved it into azure storage account as blob.

我的方法——

  1. I am creating a http trigger and call an REST api call to fetch the data from the devops repo with use of headers and the pattern url.

我在代码中添加了一些标题,例如:-

pat = 'access-token'
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')
logging.info("----------------auth--------------")
headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}
logging.info('*************headers************')
response = requests.get(
        url="https://dev.azure.com/{{organisation}}/?{{repository}}&commitOrBranch=master&api-version=5.0-preview.1&path={{path}}.json", headers=headers)
logging.info('--------------response-------------')
logging.info(response)

但这并没有给我回复中的内容。

并给出如下日志:-

2022-01-28T11:26:04Z   [Information]   ----------------auth--------------
2022-01-28T11:26:04Z   [Information]   *************headers************
2022-01-28T11:26:05Z   [Information]   --------------response-------------

跳过结果..

  1. 第二部分是将其转换为 excel,我有代码可以做到这一点,它在本地路径上运行良好。

  2. 第三步是将 excel 存储在存储帐户中。

我被卡住了,因为我没有在响应中得到任何内容,而且我是 python 的新手,我不知道如何加载 json。

第三步,如何将结果保存到存储帐户中。

感谢您提前提供任何回复,您可以询问是否需要任何详细信息。

我已编辑问题以获取更多详细信息。

I am creating a http trigger and call an REST api call to fetch the data from the devops repo with use of headers and the pattern url.

根据我在下面的工作,示例代码将帮助您以 JSON 格式从 Azure Repos 下载数据。 正如你所说,你没有得到任何回应可能是因为 PAT 令牌问题

import requests
import base64

pat = 'PAT'
authorization = str(base64.b64encode(bytes(':'+pat, 'ascii')), 'ascii')

headers = {
    'Accept': 'application/json',
    'Authorization': 'Basic '+authorization
}

response = requests.get(
    url="https://vssps.dev.azure.com/{Organization}/_apis/graph/users?api-version=6.0-preview.1", headers=headers)
print(response)

第二部分是将其转换为 excel,我有代码可以做到这一点,它在本地路径上运行良好。

您可以使用 pandas 和 openpyxl 将 JSON 文件转换为 .XLSX 文件,这里是示例代码。

import pandas
pandas.read_json("input.json").to_excel("output.xlsx")

第三步是将 excel 存储在存储帐户中。

这是使用 python 将文件上传到存储帐户的文档。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM