I am using Google's Document AI to do OCR on PDF's. I have been using this script for close to a year without issue, but now it is giving me this certificate verify failed error that I am unable to find any support on either in Google's documentation or in Stack Overflow.
_InactiveRpcError Traceback (most recent call last)
File ~\Anaconda3\lib\site-packages\google\api_core\grpc_helpers.py:72, in _wrap_unary_errors.<locals>.error_remapped_callable(*args, **kwargs)
71 try:
---> 72 return callable_(*args, **kwargs)
73 except grpc.RpcError as exc:
File ~\Anaconda3\lib\site-packages\grpc\_channel.py:1030, in _UnaryUnaryMultiCallable.__call__(self, request, timeout, metadata, credentials, wait_for_ready, compression)
1028 state, call, = self._blocking(request, timeout, metadata, credentials,
1029 wait_for_ready, compression)
-> 1030 return _end_unary_response_blocking(state, call, False, None)
File ~\Anaconda3\lib\site-packages\grpc\_channel.py:910, in _end_unary_response_blocking(state, call, with_call, deadline)
909 else:
--> 910 raise _InactiveRpcError(state)
_InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:172.217.4.74:443: Ssl handshake failed: SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED"
debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNKNOWN: ipv4:172.217.4.74:443: Ssl handshake failed: SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED {grpc_status:14, created_time:"2023-05-23T17:07:46.545432287+00:00"}"
>
The above exception was the direct cause of the following exception:
ServiceUnavailable Traceback (most recent call last)
File ~\Anaconda3\lib\site-packages\google\api_core\retry.py:191, in retry_target(target, predicate, sleep_generator, timeout, on_error, **kwargs)
190 try:
--> 191 return target()
193 # pylint: disable=broad-except
194 # This function explicitly must deal with broad exceptions.
File ~\Anaconda3\lib\site-packages\google\api_core\grpc_helpers.py:74, in _wrap_unary_errors.<locals>.error_remapped_callable(*args, **kwargs)
73 except grpc.RpcError as exc:
---> 74 raise exceptions.from_grpc_error(exc) from exc
ServiceUnavailable: 503 failed to connect to all addresses; last error: UNKNOWN: ipv4:172.217.4.74:443: Ssl handshake failed: SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
The above exception was the direct cause of the following exception:
RetryError Traceback (most recent call last)
Cell In[2], line 20
18 raw_document = documentai.RawDocument(content = image_content, mime_type = mime_type)
19 request = documentai.ProcessRequest(name = resource_name, raw_document = raw_document)
---> 20 result = docai_client.process_document(request = request)
File ~\Anaconda3\lib\site-packages\google\cloud\documentai_v1\services\document_processor_service\client.py:612, in DocumentProcessorServiceClient.process_document(self, request, name, retry, timeout, metadata)
607 metadata = tuple(metadata) + (
608 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
609 )
611 # Send the request.
--> 612 response = rpc(
613 request,
614 retry=retry,
615 timeout=timeout,
616 metadata=metadata,
617 )
619 # Done; return the response.
620 return response
File ~\Anaconda3\lib\site-packages\google\api_core\gapic_v1\method.py:113, in _GapicCallable.__call__(self, timeout, retry, *args, **kwargs)
110 metadata.extend(self._metadata)
111 kwargs["metadata"] = metadata
--> 113 return wrapped_func(*args, **kwargs)
File ~\Anaconda3\lib\site-packages\google\api_core\retry.py:349, in Retry.__call__.<locals>.retry_wrapped_func(*args, **kwargs)
345 target = functools.partial(func, *args, **kwargs)
346 sleep_generator = exponential_sleep_generator(
347 self._initial, self._maximum, multiplier=self._multiplier
348 )
--> 349 return retry_target(
350 target,
351 self._predicate,
352 sleep_generator,
353 self._timeout,
354 on_error=on_error,
355 )
File ~\Anaconda3\lib\site-packages\google\api_core\retry.py:207, in retry_target(target, predicate, sleep_generator, timeout, on_error, **kwargs)
203 next_attempt_time = datetime_helpers.utcnow() + datetime.timedelta(
204 seconds=sleep
205 )
206 if deadline < next_attempt_time:
--> 207 raise exceptions.RetryError(
208 "Deadline of {:.1f}s exceeded while calling target function".format(
209 timeout
210 ),
211 last_exc,
212 ) from last_exc
214 _LOGGER.debug(
215 "Retrying due to {}, sleeping {:.1f}s ...".format(last_exc, sleep)
216 )
217 time.sleep(sleep)
RetryError: Deadline of 120.0s exceeded while calling target function, last exception: 503 failed to connect to all addresses; last error: UNKNOWN: ipv4:172.217.4.74:443: Ssl handshake failed: SSL_ERROR_SSL: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
Here is the snippet of code giving the error. This is almost a copy and paste from Googles documentation and it worked without fail up to this point.
from google.api_core.client_options import ClientOptions
from google.cloud import documentai
import os
os.environ\["GOOGLE_APPLICATION_CREDENTIALS"\] = r"C:\\Users\\MROJKO\\Documents\\Program Files\\DOC OCR\\key.json"
project_id = "ela-converter"
location = "us"
processor_id = "f2676b8ba4deab98"
mime_type = "application/pdf"
docai_client = documentai.DocumentProcessorServiceClient(client_options = ClientOptions(api_endpoint = f"us-documentai.googleapis.com"))
resource_name = docai_client.processor_path(project_id, location, processor_id)
with open(r"Q:\\Projects\\E-40000\\E-47000\\E-47521 Electrical Load Analysis ELA for CAM ABX ATI\\Supplemental ELA Reports\\Boeing\\D281T002-55\\Split ELA Reports\\D281T002-55 1.pdf", 'rb') as image:
image_content = image.read()
raw_document = documentai.RawDocument(content = image_content, mime_type = mime_type)
request = documentai.ProcessRequest(name = resource_name, raw_document = raw_document)
result = docai_client.process_document(request = request)