0

I recently created an ASP.NET Core Web API project which communicates with a Computer Vision instance to generate image captions. To authenticate the API Server to Computer Vision, I use key credentials (I plan to switch to managed identity later). I call the Computer Vision instance using the following code:

var serviceOptions = new VisionServiceOptions(
    "https://NAME.cognitiveservices.azure.com/",
    new AzureKeyCredentials("KEY"));

using var imageSource = VisionSource.FromUrl(
     new Uri("https://learn.microsoft.com/azure/cognitive-services/computer-vision/media/quickstarts/presentation.png"));

var analysisOptions = new ImageAnalysisOptions()
{
    Features =
          ImageAnalysisFeature.CropSuggestions
        | ImageAnalysisFeature.Caption
        | ImageAnalysisFeature.DenseCaptions
        | ImageAnalysisFeature.Objects
        | ImageAnalysisFeature.People
        | ImageAnalysisFeature.Text
        | ImageAnalysisFeature.Tags
};

var analyzer = new ImageAnalyzer(serviceOptions, imageSource, analysisOptions);

var result = analyzer.Analyze();

if (result.Reason == ImageAnalysisResultReason.Analyzed)
{
    return Ok(result);
}

return NotFound(ImageAnalysisErrorDetails.FromResult(result));

Deploying this code to Azure App Service works flawlessly. Running the same code locally however, results in this error:

{
  "message": "Unknown error in sending http request",
  "errorCode": -1,
  "reason": 5
}

Requesting the captions from the Computer Vision instance directly using curl like this also works locally without issue:

curl -H "Ocp-Apim-Subscription-Key: KEY" -H "Content-Type: application/json" "https://NAME.cognitiveservices.azure.com/computervision/imageanalysis:analyze?features=caption,read&model-version=latest&language=en&api-version=2023-02-01-preview" -d "{'url':'https://learn.microsoft.com/azure/ai-services/computer-vision/media/quickstarts/presentation.png'}"
J Heschl
  • 177
  • 4
  • 15
  • Are you running behind a Firewall/Proxy Locally? Can you enable verbose logging in ASP.NET Core and see what else is shown in logs? Azure SDKs often use the underlying Azure Core library, which has logging capabilities. Enabling logging for Azure SDKs can provide more information. You can set the AZURE_LOG_LEVEL environment variable to 2 to see detailed logs. – Daredevil Aug 14 '23 at 13:05
  • No I don't run either a proxy or a firewall on my local machine/network. Settings the environment variable and grepping through the generated logs I can't find any references to the requests to the Vision Service instance being made. – J Heschl Aug 14 '23 at 14:32
  • While researching, I found this thread on Microsoft Learn which might be related: https://learn.microsoft.com/en-us/answers/questions/1325959/unknown-error-in-sending-http-request-with-azure-c – J Heschl Aug 14 '23 at 14:36
  • How about using postman for a test? – Qiang Fu Aug 15 '23 at 01:33
  • Sending a request to Computer Vision directly from my local machine with postman works as expected. – J Heschl Aug 16 '23 at 14:35

0 Answers0