4
votes

I am trying to test some images with Microsoft Azure emotion API. Following the instruction on microsoft, I get { "statusCode": 404, "message": "Resource not found" } error all the time. And my codes are modified from the website as following:

########### 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': 'key',
}

params = urllib.urlencode({ })

# Replace the example URL below with the URL of the image you want to analyze.
body = "{ 'url':'http://www.scientificamerican.com/sciam/cache/file/35391452-5457-431A-A75B859471FAB0B3.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('westcentralus.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))

Also, when I enter the endpoint url in my browser, which is https://westus.api.cognitive.microsoft.com/emotion/v1.0 , it shows { "error": { "code": "ResourceNotFound", "message": "resource not found." } }. I am not sure whether this is related to the error.

Did anybody meet this problem or can anyone give me some advice on solving the problem? Thanks!

2
did you solve this issue =? - Bala u1

2 Answers

0
votes

I've also faced the same issue, whatever the status code & error message you got

[message:protected] => Fail: Code: 404 Value: Not Found details (if any): Resource not found for the segment 'Jobs'..

Check your params, if you are passing to the azure with already processed JobId & all the stuff. Then you will get the issue. You need to cross-check whether your passing file information is already processed or not.

Thanks!

-1
votes

I tried to reproduce your issue successfully, which was caused by the westcentralus host does not exist, as below.

enter image description here

Please change the host westcentralus.api.cognitive.microsoft.com to westus.api.cognitive.microsoft.com in your code, then it works.