Getting KeyError: 'Endpoint' error in Python when calling Custom Vision API
Getting KeyError: 'Endpoint' error in Python when calling Custom Vision API
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.customvision import prediction
from PIL import Image
endpoint = "https://southcentralus.api.cognitive.microsoft.com/"
project_id = "projectidhere"
prediction_key = "predictionkeyhere"
predict = CustomVisionPredictionClient(prediction_key, endpoint)
with open("c:/users/paul.barbin/pycharmprojects/hw3/TallowTest1.jpg", mode="rb") as image_data:
tallowresult = predict.detect_image(project_id, "test1", image_data)
Python 3.7,我使用的是 Azure Custom Vision 3.1? (>azure.cognitiveservices.vision.customvision) (3.1.0)
请注意,我在 SO 上看到了同样的问题,但没有真正的解决方案。在另一个问题上发布的答案说改用 REST API。
我认为错误出在端点(如错误中所述),并且我尝试了一些变体 - 使用斜杠,不使用环境变量,不使用,我尝试附加各种字符串到我的端点,但我不断收到相同的消息。感谢任何帮助。
这里有完整的错误:
Traceback (most recent call last):
File "GetError.py", line 15, in <module>
tallowresult = predict.detect_image(project_id, "test1", image_data)
File "C:\Users\paul.barbin\PycharmProjects\hw3\.venv\lib\site-packages\azure\cognitiveservices\vision\customvision\prediction\operations\_custom_vision_
prediction_client_operations.py", line 354, in detect_image
request = self._client.post(url, query_parameters, header_parameters, form_content=form_data_content)
File "C:\Users\paul.barbin\PycharmProjects\hw3\.venv\lib\site-packages\msrest\service_client.py", line 193, in post
request = self._request('POST', url, params, headers, content, form_content)
File "C:\Users\paul.barbin\PycharmProjects\hw3\.venv\lib\site-packages\msrest\service_client.py", line 108, in _request
request = ClientRequest(method, self.format_url(url))
File "C:\Users\paul.barbin\PycharmProjects\hw3\.venv\lib\site-packages\msrest\service_client.py", line 155, in format_url
base = self.config.base_url.format(**kwargs).rstrip('/')
KeyError: 'Endpoint'
CustomVisionPredictionClient 采用两个必需的位置参数:端点和凭据。 Endpoint 需要在 credentials 之前传入,尝试调换顺序:
predict = CustomVisionPredictionClient(endpoint, prediction_key)
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
from msrest.authentication import CognitiveServicesCredentials
from azure.cognitiveservices.vision.customvision import prediction
from PIL import Image
endpoint = "https://southcentralus.api.cognitive.microsoft.com/"
project_id = "projectidhere"
prediction_key = "predictionkeyhere"
predict = CustomVisionPredictionClient(prediction_key, endpoint)
with open("c:/users/paul.barbin/pycharmprojects/hw3/TallowTest1.jpg", mode="rb") as image_data:
tallowresult = predict.detect_image(project_id, "test1", image_data)
Python 3.7,我使用的是 Azure Custom Vision 3.1? (>azure.cognitiveservices.vision.customvision) (3.1.0)
请注意,我在 SO 上看到了同样的问题,但没有真正的解决方案。在另一个问题上发布的答案说改用 REST API。
我认为错误出在端点(如错误中所述),并且我尝试了一些变体 - 使用斜杠,不使用环境变量,不使用,我尝试附加各种字符串到我的端点,但我不断收到相同的消息。感谢任何帮助。
这里有完整的错误:
Traceback (most recent call last):
File "GetError.py", line 15, in <module>
tallowresult = predict.detect_image(project_id, "test1", image_data)
File "C:\Users\paul.barbin\PycharmProjects\hw3\.venv\lib\site-packages\azure\cognitiveservices\vision\customvision\prediction\operations\_custom_vision_
prediction_client_operations.py", line 354, in detect_image
request = self._client.post(url, query_parameters, header_parameters, form_content=form_data_content)
File "C:\Users\paul.barbin\PycharmProjects\hw3\.venv\lib\site-packages\msrest\service_client.py", line 193, in post
request = self._request('POST', url, params, headers, content, form_content)
File "C:\Users\paul.barbin\PycharmProjects\hw3\.venv\lib\site-packages\msrest\service_client.py", line 108, in _request
request = ClientRequest(method, self.format_url(url))
File "C:\Users\paul.barbin\PycharmProjects\hw3\.venv\lib\site-packages\msrest\service_client.py", line 155, in format_url
base = self.config.base_url.format(**kwargs).rstrip('/')
KeyError: 'Endpoint'
CustomVisionPredictionClient 采用两个必需的位置参数:端点和凭据。 Endpoint 需要在 credentials 之前传入,尝试调换顺序:
predict = CustomVisionPredictionClient(endpoint, prediction_key)