Support Questions

Find answers, ask questions, and share your expertise

Not able to start processor group through Python requests (Rest api)

avatar

I'm trying to execute python code to start processor group and getting below error

 

Error:

Traceback (most recent call last):
400 Client Error: Bad Request for url: http://localhost:8080/nifi-api/process-groups/bee62419-016f-1000-f131-5c589af8faff
File "/Users/xxxx/Documents/Project/BU/pythonPractice/nifiTest.py", line 19, in <module>
r.raise_for_status()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: http://localhost:8080/nifi-api/process-groups/bee62419-016f-1000-f131-5c589af8faff

 

 

Code:

newUrl="http://localhost:8080/nifi-api/process-groups/bee62419-016f-1000-f131-5c589af8faff"
data1={'id':'bee62419-016f-1000-f131-5c589af8faff','state':'RUNNING'}

try:
r = requests.put(newUrl, data=data1,headers={'Content-Type': 'application/json','Accept': 'application/json','Authorization': 'Bearer [OAUTH2_TOKEN]'})
#r = requests.get(newUrl, data=data1, headers={'Content-Type': 'application/json', 'Accept': 'application/json',
# 'Accept-Charset': 'UTF-8'})

r.raise_for_status()
except requests.exceptions.RequestException as e:
print(e)
raise

 

When same thing I'm executing through curl command it working for me

 

curl -i -X PUT -H "Content-Type: application/json" -d '{"id":"bee62419-016f-1000-f131-5c589af8faff","state":"RUNNING"}' http://localhost:8080/nifi-api/flow/process-groups/bee62419-016f-1000-f131-5c589af8faff

HTTP/1.1 200 OK

Date: Mon, 20 Jan 2020 16:38:34 GMT

X-Frame-Options: SAMEORIGIN

Content-Security-Policy: frame-ancestors 'self'

X-XSS-Protection: 1; mode=block

Cache-Control: private, no-cache, no-store, no-transform

Content-Type: application/json

Vary: Accept-Encoding

Vary: User-Agent

Content-Length: 63

Server: Jetty(9.4.19.v20190610)
1 ACCEPTED SOLUTION

avatar

I found the solution myself

 

import requests

headers = {
'Content-Type': 'application/json',
}

data = '{"id":"bee62419-016f-1000-f131-5c589af8faff","state":"RUNNING"}'

response = requests.put('http://localhost:8080/nifi-api/flow/process-groups/bee62419-016f-1000-f131-5c589af8faff', headers=headers, data=data)

 

View solution in original post

2 REPLIES 2

avatar

I found the solution myself

 

import requests

headers = {
'Content-Type': 'application/json',
}

data = '{"id":"bee62419-016f-1000-f131-5c589af8faff","state":"RUNNING"}'

response = requests.put('http://localhost:8080/nifi-api/flow/process-groups/bee62419-016f-1000-f131-5c589af8faff', headers=headers, data=data)

 

avatar
Super Guru

You should be able to accept your own reply as solution marking it closed/solved.

 

One thing I do notice, which I HIGHLY recommend against is using "localhost"...