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://localhost:3000/Patient'
headers = {'Content-Type': 'application/json'}
response = post(server, headers=headers, data=payload, 
                pkcs12_filename=clientcert, 
                pkcs12_password='', 
                verify=servercert)
/usr/local/lib/python3.7/site-packages/urllib3/connection.py:394: SubjectAltNameWarning: Certificate for localhost has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/urllib3/urllib3/issues/497 for details.)
  SubjectAltNameWarning,

print(response.headers['location'])
Patient/d240c89e-b34f-4394-95a6-05fe11654998



Last update: October 23, 2020