Python API: Creating an instance doesn't like my JSON?
BMPCreated with Sketch.BMPZIPCreated with Sketch.ZIPXLSCreated with Sketch.XLSTXTCreated with Sketch.TXTPPTCreated with Sketch.PPTPNGCreated with Sketch.PNGPDFCreated with Sketch.PDFJPGCreated with Sketch.JPGGIFCreated with Sketch.GIFDOCCreated with Sketch.DOC Error Created with Sketch.
Question

Python API: Creating an instance doesn't like my JSON?

by
Lightw
Created on 2021-02-19 22:24:10 (edited on 2024-09-04 14:23:26) in Public Cloud

I am attempting to use python-ovh to simply create an instance but it is giving me trouble. The API documentation actually seems to put out invalid Python code (at least for Python3..) and I'm not sure what I'm doing wrong. I believe I'm passing correct JSON but the API doesn't like it. I am having a really hard time finding example code through searches also.

My code:

self.inst = {}
self.inst['flavorId'] = self.flavorid
self.inst['imageId'] = self.imageid
self.inst['name'] = self.name
self.inst['region'] = self.region
self.inst['monthlyBilling'] = False

try:
self.instance = client.post("/cloud/project/" + self.servicename + "/instance",
json.dumps(self.inst, separators=(",",":"))
)
except ovh.APIError as e:
print("JSON: " + json.dumps(self.inst, separators=(",",":")))
print("Ooops, failed to create instance:", e)

Debug output:

JSON: {\"flavorId\":\"14c5fa3f-fdad-45c4-9cd1-14dd99c341ee\",\"imageId\":\"92bee304-a24f-4db5-9896-864da799f905\",\"name\":\"ovhcloud-test-1\",\"region\":\"BHS5\",\"monthlyBilling\":false}

Error output:

Ooops, failed to create instance: Missing parameter(s): flavorId, name, region \nOVH-Query-ID: CA.ext-3.6101d265.2209.d74765fb-6227-4105-a24b-c46c74f3e508\n"

the API docs tell me to do this:

result = client.post('/cloud/project/xxxxxx/instance',
='{"flavorId":"14c5fa3f-fdad-45c4-9cd1-14dd99c34","imageId":"92bee304-a24f-4db5-9896-864da799f905","monthlyBilling":false,"name":"testinstance","region":"BHS5","userData":"testdata"}', // Request Body (type: cloud.ProjectInstanceCreation)
)

But that gives syntax errors and doesn't really work with variable substitution either.

Can anyone help tell me what I'm doing wrong?


Replies are currently disabled for this question.