Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Created on
01-20-2020
11:10 PM
- last edited on
01-20-2020
11:42 PM
by
VidyaSargur
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)
Created 01-21-2020 06:02 AM
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)
Created 01-21-2020 06:02 AM
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)
Created 01-21-2020 06:06 AM
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"...