[Python] How to get a YAML file from the Bitbucket Server API?

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to get a YAML file, located on our Bitbucket, in YAML format, using an API call in a Python script. The only way I have been able to get any data so far, is by using .json() at the end of the API call, and then using yaml.dump() on it.

    As I am new to Python, I don't know if it's a stupid mistake or not, but I have looked at some documentation and not found the answer yet.

    Please note that I have replaced some data with dummy values in the API call to for security reasons, and I am sure the API call itself is not the problem, since I am receiving the right data, but in the wrong format. Thus, I am looking for a way to either request it in YAML format, or convert it to YAML format.

    import requests
    import yaml

    composefile = yaml.dump(requests.get('https://our-company-bitbucket-url.io/rest/api/latest/projects/our-project/repos/our-repo/browse/reporting-distribution-resources/src/main/resources/docker/docker-compose.yml', headers={'Authorization': 'Bearer SUPERSECRETAUTHENTICATIONTOKEN69'}).json())

    print(composefile)


    The print command prints the following:

    isLastPage: true
    limit: 500
    lines:
    - text: 'version: ''2.0'''
    - text: 'services:'
    - text: ' installer:'
    - text: ' image: url-to-image'
    - text: ' labels:'
    - text: ' io.portainer.accesscontrol.public: "public"'
    ...

    Continue reading...

Compartilhe esta Página