Support Questions
Find answers, ask questions, and share your expertise

Receiving 400 Bad Request on PUT against Ranger API (Python requests)

Receiving 400 Bad Request on PUT against Ranger API (Python requests)

Explorer

Summary. Submitting a PUT request against the Ranger API: https://cwiki.apache.org/confluence/display/RANGER/REST+APIs+for+Policy+Management#RESTAPIsforPolicy.... I can create the policy fine, but seems with PUT, I get bad request and cannot determine why. The problem is not the content, as I can copy another policy as test.json and try to PUT that

Code snip

HEADERS = {'Content-type': 'application/json'}
result = requests.put(URL_BASE + URL_POLICY + policy_id, headers=HEADERS, data=open(json_file, 'rb'), auth=requests.auth.HTTPBasicAuth(USERNAME, PASSWORD))

Headers on GET

Retrieving and exporting policy 16: <POLICY_NAME> {'transfer-encoding': 'chunked', 'set-cookie': 'RANGERADMINSESSIONID=<ID>; Path=/; HttpOnly, hadoop.auth=; Path=/; Domain=HOST.DOMAIN.COM; Expires=Thu, 01-Jan-1970 00:00:00 GMT; HttpOnly', 'server': 'Apache-Coyote/1.1', 'date': 'Tue, 29 Aug 2017 14:57:25 GMT', 'x-frame-options': 'DENY', 'content-type': 'application/json', 'www-authenticate': 'Negotiate'}

Headers on successful POST

{'transfer-encoding': 'chunked', 'set-cookie': 'RANGERADMINSESSIONID=<ID>; Path=/; HttpOnly, hadoop.auth=; Path=/; Domain=HOST.DOMAIN.COM; Expires=Thu, 01-Jan-1970 00:00:00 GMT; HttpOnly', 'server': 'Apache-Coyote/1.1', 'date': 'Tue, 29 Aug 2017 15:34:04 GMT', 'x-frame-options': 'DENY', 'content-type': 'application/json', 'www-authenticate': 'Negotiate'} Policy applied <POLICY_NUM>

Headers on PUT (400 respose)

Submitting PUT API request: http://HOST:PORT/service/public/api/policy/<POLICY_NUM>; {'transfer-encoding': 'chunked', 'set-cookie': 'RANGERADMINSESSIONID=<ID>; Path=/; HttpOnly, hadoop.auth=; Path=/; Domain=HOST.DIOMAIN.COM; Expires=Thu, 01-Jan-1970 00:00:00 GMT; HttpOnly', 'server': 'Apache-Coyote/1.1', 'connection': 'close', 'date': 'Tue, 29 Aug 2017 15:19:58 GMT', 'x-frame-options': 'DENY', 'content-type': 'application/json', 'www-authenticate': 'Negotiate'}

The object exists at the endpoint, so a PUT needs made.

## Expected Result

Response code 200

## Actual Result

Traceback (most recent call last): File "ranger-policy-manager.py", line 183, in <module> result.raise_for_status() File "/usr/lib/python2.7/site-packages/requests/models.py", line 834, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 400 Client Error: Bad Request 
1 REPLY 1

Re: Receiving 400 Bad Request on PUT against Ranger API (Python requests)

Guru

Hello @Michael DeGuzis,

I have seen this issue due to bad policy content. Can you please paste the content of policy JSON that you are trying to upload?

Thanks.