I am trying to use the azure service-Computer vision for analyzing an Image with python3.7. While trying to make a connection request, an error is shown. It looks like the parameter(url) I am giving for httpsConnection is wrong, But I dont know how to rectify it.
The problem is with the API endpoint. The endpoint I have given is correct but the parameter is asking for integer value(that's what I understood).
def analyze_image(data):
try:
conn = http.client.HTTPSConnection('https://xxx.cognitiveservices.azure.com/')
conn.request("POST", "/vision/v1.0/analyze?%s" % params, str(data), headers)
response = conn.getresponse()
data = response.read()
print(str(data))
conn.close()
except Exception as e:
print("[Errno {0}] {1}".format(e.errno, e.strerror))
return data
Error:
Traceback (most recent call last):
File "C:\Users\Rupali Singh\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 887, in _get_hostport
port = int(host[i+1:])
ValueError: invalid literal for int() with base 10: '//rupali.cognitiveservices.azure.com/'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Rupali Singh/PycharmProjects/Drishti/ms_visionapi.py", line 44, in analyze_image
conn = http.client.HTTPSConnection('https://rupali.cognitiveservices.azure.com/')
File "C:\Users\Rupali Singh\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 1373, in __init__
blocksize=blocksize)
File "C:\Users\Rupali Singh\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 851, in __init__
(self.host, self.port) = self._get_hostport(host, port)
File "C:\Users\Rupali Singh\AppData\Local\Programs\Python\Python37\lib\http\client.py", line 892, in _get_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
http.client.InvalidURL: nonnumeric port: '//rupali.cognitiveservices.azure.com/'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/Rupali Singh/PycharmProjects/Drishti/ms_visionapi.py", line 85, in <module>
data = analyze_image(img)
File "C:/Users/Rupali Singh/PycharmProjects/Drishti/ms_visionapi.py", line 51, in analyze_image
print("[Errno {0}] {1}".format(e.errno, e.strerror))
AttributeError: 'InvalidURL' object has no attribute 'errno'
Process finished with exit code 1