Basic query in python
Duplicate a simple cURL query in Python.
This example is available in the Jupyter notebook at: github.com/intrahealth/client-registry-docs/notebooks/simple_query_in_python.ipynb
curl --cert sampleclientcertificates/openmrs.p12 --cert-type p12 --cacert certificates/server_cert.pem -d @/Users/richard/src/github.com/openhie/client-registry/DemoData/patient1_openmrs.json -H "Content-Type: application/json" -XPOST https://localhost:3000/Patient
#!/usr/bin/env python3
from pathlib import Path
# import requests
from requests_pkcs12 import get, post
# path to your git clone of github.com/intrahealth/client-registry
crhome = Path.home() / 'src' / 'github.com' / 'intrahealth' / 'client-registry'
clientcert = crhome / 'server' / 'sampleclientcertificates' / 'openmrs.p12'
servercert = crhome / 'server' / 'certificates' / 'server_cert.pem'
csv_file = crhome / 'tests' / 'uganda_data_v21_20201501.csv'
payload_bytes = crhome / 'DemoData' / 'patient1_openmrs.json'
payload = open(payload_bytes)
server = 'https://167.172.131.240:3000/Patient'
headers = {'Content-Type': 'application/json'}
response = post(server, headers=headers, data=payload,
pkcs12_filename=clientcert,
pkcs12_password='',
verify=servercert)
print(response.headers['location'])
Last update: April 13, 2020