-
Notifications
You must be signed in to change notification settings - Fork 1
/
Emotion_API.py
31 lines (25 loc) · 1.18 KB
/
Emotion_API.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
########### Python 2.7 #############
import httplib, urllib, base64
headers = {
# Request headers. Replace the placeholder key below with your subscription key.
'Content-Type': 'application/json',
'Ocp-Apim-Subscription-Key': 'a6a9555023d74986a23d4a6935274f88',
}
params = urllib.urlencode({
})
# Replace the example URL below with the URL of the image you want to analyze.
body = "{ 'url': 'https://psychology.iresearchnet.com/wp-content/uploads/2016/01/Anger-1.jpg' }"
try:
# NOTE: You must use the same region in your REST call as you used to obtain your subscription keys.
# For example, if you obtained your subscription keys from westcentralus, replace "westus" in the
# URL below with "westcentralus".
conn = httplib.HTTPSConnection('westus.api.cognitive.microsoft.com')
conn.request("POST", "/emotion/v1.0/recognize?%s" % params, body, headers)
response = conn.getresponse()
data = response.read()
print(data)
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
#https://westus.api.cognitive.microsoft.com/face/v1.0
#https://westus.api.cognitive.microsoft.com/emotion/v1.0