Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

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

Solved Go to solution

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

New Contributor

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

Accepted Solutions
Highlighted

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

New Contributor

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
Highlighted

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

New Contributor

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

Highlighted

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

Master Collaborator

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"...  

 


 


If this answer resolves your issue or allows you to move forward, please choose to ACCEPT this solution and close this topic. If you have further dialogue on this topic please comment here or feel free to private message me. If you have new questions related to your Use Case please create separate topic and feel free to tag me in your post.  


 


Thanks,



Steven

Don't have an account?
Coming from Hortonworks? Activate your account here