1

I'm using Python 2.7 and trying to run the sample python code from this website

########### Python 2.7 #############
import httplib, urllib, base64

headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.urlencode({
    # Request parameters
    'maxCandidates': '1',
})

try:
    conn = httplib.HTTPSConnection('api.projectoxford.ai')
    conn.request("POST", "/vision/v1.0/describe?%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))

####################################

########### Python 3.2 #############
import http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
    # Request headers
    'Content-Type': 'application/json',
    'Ocp-Apim-Subscription-Key': '{subscription key}',
}

params = urllib.parse.urlencode({
    # Request parameters
    'maxCandidates': '1',
})

try:
    conn = http.client.HTTPSConnection('api.projectoxford.ai')
    conn.request("POST", "/vision/v1.0/describe?%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))

####################################

It's the Computer Vision API that describes an image.


I'm getting the following error:

Python handling socket.error: [Errno 104] Connection reset by peer

What should be the problem?

Let me know if you need any other information.

mkierc
  • 1,193
  • 2
  • 15
  • 28
  • Possible duplicate of [Python handling socket.error: \[Errno 104\] Connection reset by peer](http://stackoverflow.com/questions/20568216/python-handling-socket-error-errno-104-connection-reset-by-peer) – jeerbl Sep 19 '16 at 22:49
  • Thats because your client is stopped or may internet in client goes off or – Prabhu Dec 06 '16 at 12:22

0 Answers0