import requests


def analyzeImg(imgResp, apiKey):
	"""
	Sends encoded image through Microsoft computer vision API to get tags and categories.
	Args:
		imgResp: image response from urlopening webcam image
		apiKey: Computer Vision API key
	Returns:
		json object with 'categories' and 'tags' as keys
	"""
	headers = {
	  'content-type':'application/octet-stream',
	  'Ocp-Apim-Subscription-Key': apiKey
	}

	params = {
	  'visualFeatures': 'Categories,Tags,Description'
	}

	baseUrl = 'https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/analyze'
	
	response = None
	try:
		response = requests.post(baseUrl, params=params, headers=headers, data=imgResp)
	except requests.exceptions.RequestException as e:
		print(e)
		return ''
	categories = response.json()
	return categories