I am trying to stop a running server instance on Openstack Nova. I am using the following API as a reference
https://developer.openstack.org/api-ref/compute/#stop-server-os-stop-action
The following is my code snippet
import openstack.config
self.cloud_region = openstack.config.OpenStackConfig().get_one('adminproject')
self.session = self.cloud_region.get_session_client('compute')
I am able to make GET requests to the server
response = self.session.get(url)
But when i try to make POST requests, I am getting errors. This is how I am trying to do it
url = "/servers/" + vm_id + "/action
body = {"os-stop":"null"}
reponse = self.session.post(url, {'os-stop' : 'null'})
TypeError: post() takes exactly 2 arguments (3 given)
I have also tried
reponse = self.session.post(url, body=body)
which gives me an error
TypeError: request() got an unexpected keyword argument 'body'
When i do it via the nova client and enable the debug mode, this is what i get
curl -g -i -X POST http://IP:PORT/v2.1/12bf80bc27cf4fdc87a2ce2cb0619159/servers/93bc82d4-7a3b-4f67-bc6e-dfb2553a57fc/action -H "Accept: application/json" -H "Content-Type: application/json" -H "User-Agent: python-novaclient" -H "X-Auth-Token: {SHA1}447e97116c71efcff1a02f4d7fdf8d76a4490d9d" -d '{"os-stop": null}'
It would be great if someone can help in finding out how to emulate the above request.
TIA.
Related
I am trying to convert a curl call to python request . The curl call looks like
$ curl -b $COOKIE_FILE \
-X FIND $URL \
-H 'Content-Type: application/json; charset=utf-8' \
I tried using request to get the correct response via requests.post() but i could not get the correct response. Can someone help me with this
Requests allows using arbitrary request methods with the request function, take a look at the documentation.
For example this is how it would look with a Session() object:
import requests
with requests.Session() as sess:
sess.headers = {
#headers in dict format, you could add cookies here too(or set it to sess.cookies)
}
response = sess.request("FIND", url)
I am able to call private user API through code like this:
curl -X POST -H "Accept: application/json" -H "API-Key: mykey" -H "API-Sign: mysign" -d "nonce=123" https://api.kraken.com/0/private/Balance
feedback is telling me how much USD and ETH i have left in my account.
but when I switch to this trying to send order:
curl -X POST -H "Accept: application/json" -H "API-Key: mykey" -H "API-Sign: mysign" -d "nonce=123" 'https://api.kraken.com/0/private/AddOrder?pair=XXBTZUSD&type=buy&ordertype=market&volume=0.01'
it says {"error":["EGeneral:Invalid arguments"]}, how can i fix it?
It seems you need to set the Content-Type header to whatever it is. In this case application/x-www-form-urlencoded. Bit odd that it's not in the docs.
I have a URL like below that I use for query
http://<ip>:<port>/api/test/computers?token=a124af&criteria={"and":[["name","=","comp_name"]]}
I was writing a script for this and using curl to download the results from the url. But I am not able to get curl to work. Here is what i tried
curl http://<ip>:<port>/api/test/computers?token=a124af&criteria={"and":[["name","=","comp_name"]]}
-- This runs curl http://:/api/test/computers?token=a124af in background mode.
I know I can pass json data like curl -H "Content-Type: application/json" --data '' . But in this case I have a mix of json as well as other data. How can i achieve that? this does not seem to work
curl -H "Content-Type: application/json" --data "{"and":[["name","=","comp_name"]]}" "http://<ip>:<port>/api/test/computers?token=a124af&criteria="
I have a POST method in my API which uses multipart encoded form data. I have set up the correct header and data settings so that the mashape web interface generated the following curl:
curl -X POST --include 'https://sslavov-text-analytics-v1.p.mashape.com/news' \
-H 'Authorization: Basic ***********' \
-H 'X-Mashape-Key: ************' \
-H 'Content-Type: multipart/form-data' \
-F 'file=#sample.docx' \
-F 'meta={"documentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"};type=application/json'
Basically i'm trying to upload a file with a simple paragraph of text for processing. The curious part is that when I run this exact curl in a bash script, everything works smoothly, but when I try to run it through mashape, it says either 400 Bad Request or 500 Internal Server Error
In my particular case, these errors are generated when I don't pass correct form or headers. So my question is: Is there an error in the curl syntax or should I keep looking for the error on server side?
EDIT: I figured out what the problem was. -F 'file=#sample.docx' was passed before -F 'meta....' and that was causing the 500 Internal Server Error So now the question is: Is there any way to specifically arrange the order of the form fields (because mashape rearranges them aplhabetically)?
I'm fairly new To Parse with Rest Api
I wanna test samples in Their Webistes's ( Here ) in Postman But every time I Post it gives me following Authentication error :
I Wanna test following code in Postman ( see origin here )
curl -X POST \
-H "X-Parse-Application-Id: 0VoIZO8cgmnyfiuklLLkKkxOX7r" \
-H "X-Parse-REST-API-Key: UjU5eb5zjic75mPZVdHExYqnneT" \
-H "Content-Type: application/json" \
-d '{
"deviceType": "ios",
"deviceToken": "0123456789abcdef0123456789cdef0123456789abcdef",
"channels": [
""
]
}' \
https://api.parse.com/1/installations
How Can I resolve this issue ? What is that ? And What is required ?
You are reqeuesting GET request and api doc says its POST request.
1) Enter correct url and select POST request method. Add required headers as per the doc.
2) Enter raw JSON data in your request body.
3) You will receive your output. Since api key and application id is not valid so that I received unauthorized error.