import requests
from requests_toolbelt import MultipartEncoder

import cv2 
import time

adress = 'localhost'
port = 1234

img = cv2.imread("image2.jpg")
img_str = cv2.imencode('.jpg', img)[1].tobytes() 

print(len(img_str))

sess = requests.Session() 


while True:
	t1 = time.time()
	multipart_data = MultipartEncoder(
	fields={
		'image': ('image', img_str, 'application/octet-stream')		
	}
)
	x1 = sess.post(
		"http://{}:{}/ImageInference".format(adress,port),
		data = multipart_data,
		headers={'Content-Type': multipart_data.content_type}
		)
	print(x1)
	print(x1.text)
	print("Time period:",time.time()-t1)

