The payload variable just needs to be single quoted.
$ python --version
Python 2.7.10
$ more test.py
import requests
s = requests.Session()
payload = '{"type": "APISession", "version": {"type": "APIVersion", "major": 1, "minor": 10, "micro": 5}}'
url='http://172.16.160.195/resources/json/delphix/session'
headers = {"content-type": "application/json"}
d = s.post(url, data=payload, headers=headers)
print(s.cookies)
print(d.text)
$ python test.py
<RequestsCookieJar[<Cookie JSESSIONID=FD93A1B19AE03029735756FC968A4E52 for 172.16.160.195/resources>]>
{"type":"OKResult","status":"OK","result":{"type":"APISession","version":{"type":"APIVersion","major":1,"minor":10,"micro":5},"locale":null,"client":null},"job":null,"action":null}
$
------------------------------
Alan Bitterman
Principal Solutions Engineer
Delphix
------------------------------
Original Message:
Sent: 06-10-2020 12:55:19 PM
From: Corey Brune
Subject: Python create API session (newbie)
Hello Srini,
You may want to take a look at our Python SDK available on Pipy (pip install delphixpy). It has all of the APIs in Python so you don't have to format JSON requests. We have a GitHub repo with Python3 (https://github.com/delphix/delphixpy-examples/blob/python3-api-1-10-2/lib/get_session.py) and Python2 (https://github.com/delphix/delphixpy-examples).
Here's an example of getting a session using delphixpy:
https://github.com/delphix/delphixpy-examples/blob/python3-api-1-10-2/lib/get_session.py
Otherwise, you will need to POST username, password, namespace in the payload.
------------------------------
Corey Brune
Technical Manager
Delphix
Original Message:
Sent: 06-10-2020 12:24:24 PM
From: Srinivasan Ramaswamy
Subject: Python create API session (newbie)
Hey, am trying to establish a python session to am stuck.
import requestss = requests.Session()payload = {"type": "APISession", "version": {"type": "APIVersion", "major": 1, "minor": 10, "micro": 5}}url='http://host_name/resources/json/delphix/session'headers = {"content-type": "application/json"}d = s.post(url, data=payload, headers=headers)print(s.cookies)print(d.text)----------------------------------------<RequestsCookieJar[<Cookie JSESSIONID=D2847C4763D84E880BA66DB427EB536F for host_name.local/resources>]>{"type":"ErrorResult","status":"ERROR","error":{"type":"APIError","details":"Syntax error in JSON input: Unrecognized token 'version': was expecting ('true', 'false' or 'null')\n at [Source: (BufferedInputStream); line: 1, column: 9]","action":"Correct the error and try again.","id":"exception.webservices.api.input.invalid.json","commandOutput":null,"diagnoses":[]}}
Am not sure what is that am missing here.
------------------------------
Srini
------------------------------