Using the Server API with Pyhon

Asked 1 years ago, Updated 1 years ago, 66 views

I am trying to use the API with Conoha, which provides the server, but it has failed.
What I want to do is add servers using API.
https://www.conoha.jp/docs/compute-create_vm.html

The user token and image vm plan uuid have already been retrieved using a different API.
The page contains request parameters and request json.
I would like to post the header and json data at the same time, but is the code as below?
An error similar to the following appears:I'm not sure if the post is okay.

{'bad request':{'message':'Missing flavorRefattribute','code':400}

import requests
import json

json_data2 = {
    "server": {
        "imageRef": aaa,
        "flavorRef": bbb,
        "adminPass": "ccc"
    }
}
farm={"X-Auth-Token":dd}
    url4="https://compute.tyo1.conoha.io/v2/0ff2f439801145a6a44bfd9488fd360e/servers"
    res4=requests.post(url=url4,json=json_data2,data=json.dumps(parm))
    print("\n")
    print(less4.status_code)
    print(less4.json())
    print(less4)
    print()

python api conoha

2022-09-30 21:30

1 Answers

The following page describes how to use requests.
http://docs.python-requests.org/en/latest/user/quickstart/ #custom-headers

The header appears to be headers=, so

res4=requests.post(url=url4,json=json_data2,headers=parm)

How about

Also, I feel that you are mistaken.
For that page in ConoHa, see
If Request Parameters is the specification of the request and Request Json is an example of JSON data to be sent at POST, please read it in the example written in Request Json.


2022-09-30 21:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.