ovh / python-ovh

Thin wrapper around OVH's APIs. Handles all the hard work including credential creation and requests signing.
https://pypi.org/project/ovh/
Other
296 stars 81 forks source link

Python Code from Console not working #124

Open cmiuser opened 1 year ago

cmiuser commented 1 year ago

Trying to create a kube cluster from API in Python. So I ran the command from the API Console and picked the Python code being generated. But at the time of testing it, once authenticated, the code to call the post command seems to be incorrect:

result = client.post('/cloud/project/<serviceID>/kube', 
    ='{"name":"test1","nodepool":{"antiAffinity":false,"autoscale":false,"desiredNodes":1,"flavorName":"d2-4","monthlyBilled":false,"name":"nodepool1"},"privateNetworkId":"A-private-network-id","region":"DE1","updatePolicy":"NEVER_UPDATE","version":"1.26"}', // Request Body (type: cloud.ProjectKubeCreation)
)

In fact, the code seems syntactically incorrect. I made this fix:

result = client.post('/cloud/project/<serviceID>/kube', 
    '{"name":"test1","nodepool":{"antiAffinity":false,"autoscale":false,"desiredNodes":1,"flavorName":"d2-4","monthlyBilled":false,"name":"nodepool1"},"privateNetworkId":"A-private-network-id","region":"DE1","updatePolicy":"NEVER_UPDATE","version":"1.26"}' )

And now at least is tried to run, but fires an exception "The input that you provided isn't valid JSON or not well formatted". I've also tried to build a dict with all the parameters, then dump it into json format, but same error appeared.

It seems the code generated by the console is not ok.

myanesp commented 6 months ago

Hi @cmiuser!

I'm facing the same problem with a POST request to create a new record (/domain/zone/{zoneName}/record) with this:

result = client.post(f'/domain/zone/{zone_name}/record', f'{{"fieldType":"A","subDomain":"{sub}","target":"{ip}","ttl":{ttl}}}', )

I've tried too without predefined variables, and the same: ovh.exceptions.BadParametersError: The input that you provided isn't valid JSON or not well formatted. I did the POST request through the web interface () and copy the code from the Python tab, and when pasting in my script, it raises the same error.

Did you manage to solve it?

Thanks

cmiuser commented 6 months ago

Hi @myanesp

I'm afraid I didn't. I finally stopped the K8S development a few months ago, as we are heading toward somewhere else now, so stopped trying.

Regards