402 implies the server doesn't like the request, and I think jimmo's point is worth looking into. Looking at (macro)python's requests , it does switch the content-type if the json parameter is not none.
from requests.models.py:
Code: Select all
if not data and json is not None:
# urllib3 requires a bytes-like body. Python 2's json.dumps
# provides this natively, but Python 3 gives a Unicode string.
content_type = 'application/json'
...
Code: Select all
else:
# Multi-part file uploads.
if files:
(body, content_type) = self._encode_files(files, data)
else:
if data:
body = self._encode_params(data)
if isinstance(data, basestring) or hasattr(data, 'read'):
content_type = None
else:
content_type = 'application/x-www-form-urlencoded'
so try switching content-type to `application/json`.