Wunderfitz / harbour-wunderfitz

A mobile dictionary application for SailfishOS
GNU General Public License v2.0
12 stars 10 forks source link

"Host requires authentication" error when performing OCR #37

Closed llewelld closed 2 years ago

llewelld commented 3 years ago

When attempting to OCR the text, the Azure endpoint refuses access. The error output to the logs is the following.

[W] unknown:0 - CloudApi::handleOcrUploadError: 204 "Host requires authentication" "{\"error\":{\"code\":\"401\",\"message\":\"Access denied due to invalid subscription key or wrong API endpoint. Make sure to provide a valid key for an active subscription and use a correct regional API endpoint for your resource.\"}}"

I entered both my Text Translator and Computer Vision API keys into the app. However, it looks like the problem may be due to the endpoint URL Wunderfitz uses to access the service.

Looking at the source, the Azure endpoint URL appears to be hardcoded to https://westeurope.api.cognitive.microsoft.com/vision/v1.0/ocr, whereas the URL provided to me for use in the Azure portal is https://wunderfitz.cognitiveservices.azure.com/.

The translator URL provided by the Azure portal is https://api.cognitive.microsofttranslator.com/ which matches that in the source code.

When creating the computer vision service I chose "northeurope" as my region and "Wunderfitz" as the resource name.

Wunderfitz commented 3 years ago

I have to admit that I haven't use the service for ages (no travel outside of German-speaking countries since COVID). I might have missed a URL change as well. No idea if I have time in the next days to test it - if you can confirm with a rebuild and a new URL that it works, I would accept a PR blindly. ;)

llewelld commented 3 years ago

I've created a PR (#38), but I'm afraid it's only draft and only good to demonstrate the issue, since what it really needs is configurable values for the resource name and region.

If I get the chance I'll try to update the PR over the next week to allow these settings to be configured through the UI (or failing that, through the Settings file at least).

Wunderfitz commented 2 years ago

Fixed with #38, thanks again!