Python – REST API call example with a self certificated SSL connection

import time
import http.client
import ssl
import json

conn = http.client.HTTPSConnection("localhost:9990", timeout=5, context=ssl._create_unverified_context())

csvFileDat = ""
with open("c:\\tmp\\test.csv") as inputFile:
    csvFileDat =

headers = {
    'content-type': "text/plain",
    'authorization': "Basic base64encoded"

sumTotal = 0

repeatCount = 100
for idx in range(repeatCount):
    start = time.time()

    conn.request("PUT", "/rest/import", csvFileDat, headers)

    res = conn.getresponse()
    data =

    end = time.time()
    elapse = end - start
    sumTotal += elapse

    result = json.loads(data.decode('utf-8'))

print("Total time: {}, Avg: {}".format(sumTotal, sumTotal / repeatCount))

This entry was posted in Programming, python and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s