soap117 / DeepRule

BSD 3-Clause "New" or "Revised" License
129 stars 45 forks source link

API Key Permission denied error; HTTPError at 401 Client Error: PermissionDenied for url: https://westus2.api.cognitive.microsoft.com/vision/v2.0/read/core/asyncBatchAnalyze?language=unk&detectOrientation=true #16

Open sidharthrai opened 2 years ago

sidharthrai commented 2 years ago

Hi All,

I was hoping if you can help me. I was trying to run the DeepRule repo. I have ran it before; it was working just fine. I tried using it recently, I'm getting the stated error below.

When I give the command python manage.py runserver 8800 the upload photo page works fine but when I upload a photo, the following error shows up.

On Website HTTPError at 401 Client Error: PermissionDenied for url: https://westus2.api.cognitive.microsoft.com/vision/v2.0/read/core/asyncBatchAnalyze?language=unk&detectOrientation=true

Request Method: POST

http://127.0.0.1:8800/ 2.2.5 HTTPError 401 Client Error: PermissionDenied for url: https://westus2.api.cognitive.microsoft.com/vision/v2.0/read/core/asyncBatchAnalyze?language=unk&detectOrientation=true /home/sidharth/anaconda3/envs/DeepRule/lib/python3.6/site-packages/requests/models.py in raise_for_status, line 940 /home/sidharth/anaconda3/envs/DeepRule/bin/python 3.6.5 ['/home/sidharth/Documents/DeepRule2', '/home/sidharth/anaconda3/envs/DeepRule/lib/python36.zip', '/home/sidharth/anaconda3/envs/DeepRule/lib/python3.6', '/home/sidharth/anaconda3/envs/DeepRule/lib/python3.6/lib-dynload', '/home/sidharth/.local/lib/python3.6/site-packages', '/home/sidharth/anaconda3/envs/DeepRule/lib/python3.6/site-packages', '/home/sidharth/anaconda3/envs/DeepRule/lib/python3.6/site-packages/azureml/_project/vendor'] Tue, 4 Jan 2022 20:32:49 +0000

On Terminal We met some errors! Internal Server Error: / Traceback (most recent call last): File "/home/sidharth/anaconda3/envs/DeepRule/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/sidharth/anaconda3/envs/DeepRule/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/sidharth/anaconda3/envs/DeepRule/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/sidharth/Documents/DeepRule2/server_match/view.py", line 30, in get_group plot_area, image_painted, data, chart_data = test('static/target.png', min_value_official=min_value, max_value_official=max_value) File "/home/sidharth/Documents/DeepRule2/test_pipeline.py", line 232, in test title2string, min_value, max_value = try_math(image_path, cls_info) File "/home/sidharth/Documents/DeepRule2/test_pipeline.py", line 164, in try_math word_infos = ocr_result(image_path) File "/home/sidharth/Documents/DeepRule2/test_pipeline.py", line 130, in ocr_result response.raise_for_status() File "/home/sidharth/anaconda3/envs/DeepRule/lib/python3.6/site-packages/requests/models.py", line 940, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 401 Client Error: PermissionDenied for url: https://westus2.api.cognitive.microsoft.com/vision/v2.0/read/core/asyncBatchAnalyze?language=unk&detectOrientation=true [05/Jan/2022 15:01:43] "POST / HTTP/1.1" 500 114613

BTW it API and key are in the ocr.py file.

My best guess is, the error coming because this project is using some Microsoft API and the key written in the system expired starting of 2022. Please let me know if that is the case or if I'm missing something. I will appreciate it if you can help. Please let me know if you have any questions for me.

soap117 commented 2 years ago

subscription_key = "ad143190288d40b79483aa0d5c532724" vision_base_url = "https://westus2.api.cognitive.microsoft.com/vision/v2.0/" ocr_url = vision_base_url + "read/core/asyncBatchAnalyze" headers = {'Ocp-Apim-Subscription-Key': subscription_key, 'Content-Type': 'application/octet-stream'} params = {'language': 'eng', 'detectOrientation': 'true'}

you may need to replace the Microsoft OCR key, the key in the original code may just be expired.

sidharthrai commented 2 years ago

Is there any way around running the code without using the Microsoft OCR key? Can we skip it? Or by any chance can you update the code with a new key? Thank you so much.