Error requesting data in ConoHa API

Asked 2 years ago, Updated 2 years ago, 44 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.When I checked it, I think it is made according to the procedure below.
1.Issuing tokens https://www.conoha.jp/docs/identity-post_tokens.html
2. Add VM https://www.conoha.jp/docs/compute-create_vm.html

Could you please point out the mistake as I received a 404 bad request error when I gave the parameters from site 1 to the request?This is my first time using the API, so something basic might be wrong.There is no problem with endpoints.

import requests
import json

defmain()->None:
url='https://identity.tyo1.conoha.io/v2.0/tokens '
data={ "username": "aaa", "password": "bbb", "tenantId": "ccc"}
res=requests.post(url=url,params=data)
print(res.status_code)
print(res.json())

if name=='main':
main()

python api

2022-09-30 17:41

1 Answers

https://www.conoha.jp/docs/identity-post_tokens.html has
It is written to send a Json format string (for example, '{"auth":{"passwordCredentials":{"username":"ConoHa", "password":"paSSword123456#$%", "tenantId":"487727e3921d44e3bfe7ebbbbf085e"}}}' as data.

The code in the question is trying to send an associative array ("username": "aaa", "password": "bbb", "tenantId": "ccc"}.

This is probably part of the reason for the bad request error.


2022-09-30 17:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.