Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSLCertVerificationError when using LlamaParse #134

Open
bhishanpdl opened this issue Apr 5, 2024 · 0 comments
Open

SSLCertVerificationError when using LlamaParse #134

bhishanpdl opened this issue Apr 5, 2024 · 0 comments

Comments

@bhishanpdl
Copy link

bhishanpdl commented Apr 5, 2024

I am trying to run the basic llama-parse notebooks from the official example. But, my computer is running behind a firewall and needs certificates to access the websites.

I got SSL certificate error when running simple LlamaParse function.

My attempts

  • Downloaded certificates for llamaindex.ai website. Also tried cloud_llamaindex.ai website. Both did not work.
  • Can we pass the parameter such as verify=path_to_cafile (as like in requests.get)
  • I do not see any website name in the error message for which the SSL verification is failing.

Code

import os

# environment setup
# os.environ["REQUESTS_CA_BUNDLE"] = os.path.expanduser('~/.certificates/llamaindex_ai.crt')
os.environ["REQUESTS_CA_BUNDLE"] = os.path.expanduser('~/.certificates/cloud_llamaindex_ai.crt')

#========= cloud key
config = {'token_llama': 'my actual api key'}
os.environ['LLAMA_CLOUD_API_KEY'] = config.get('token_llama')

#============= async
# llama-parse is async-first, running the sync code in a notebook requires the use of nest_asyncio
import nest_asyncio
nest_asyncio.apply()

# main code
from llama_parse import LlamaParse
documents = LlamaParse(result_type="text").load_data("./attention.pdf")

Another failed attempt

# main code
from llama_parse import LlamaParse
documents = LlamaParse(result_type="text",verify=False).load_data("./attention.pdf")

Error

Error while parsing the file './attention.pdf': [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1006)
---------------------------------------------------------------------------
SSLCertVerificationError                  Traceback (most recent call last)
Cell In[7], line 3
      1 from llama_parse import LlamaParse
----> 3 documents = LlamaParse(result_type="text").load_data("./attention.pdf")

File [~\venv\py311_llama_index\Lib\site-packages\llama_parse\base.py:330](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/llama_parse/base.py#line=329), in LlamaParse.load_data(self, file_path, extra_info)
    328 """Load data from the input path."""
    329 try:
--> 330     return asyncio.run(self.aload_data(file_path, extra_info))
    331 except RuntimeError as e:
    332     if nest_asyncio_err in str(e):

File [~\venv\py311_llama_index\Lib\site-packages\nest_asyncio.py:30](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/nest_asyncio.py#line=29), in _patch_asyncio.<locals>.run(main, debug)
     28 task = asyncio.ensure_future(main)
     29 try:
---> 30     return loop.run_until_complete(task)
     31 finally:
     32     if not task.done():

File [~\venv\py311_llama_index\Lib\site-packages\nest_asyncio.py:98](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/nest_asyncio.py#line=97), in _patch_loop.<locals>.run_until_complete(self, future)
     95 if not f.done():
     96     raise RuntimeError(
     97         'Event loop stopped before Future completed.')
---> 98 return f.result()

File [~\AppData\Local\Programs\Python\Python311\Lib\asyncio\futures.py:203](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/AppData/Local/Programs/Python/Python311/Lib/asyncio/futures.py#line=202), in Future.result(self)
    201 self.__log_traceback = False
    202 if self._exception is not None:
--> 203     raise self._exception.with_traceback(self._exception_tb)
    204 return self._result

File [~\AppData\Local\Programs\Python\Python311\Lib\asyncio\tasks.py:277](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/AppData/Local/Programs/Python/Python311/Lib/asyncio/tasks.py#line=276), in Task.__step(***failed resolving arguments***)
    273 try:
    274     if exc is None:
    275         # We use the `send` method directly, because coroutines
    276         # don't have `__iter__` and `__next__` methods.
--> 277         result = coro.send(None)
    278     else:
    279         result = coro.throw(exc)

File [~\venv\py311_llama_index\Lib\site-packages\llama_parse\base.py:311](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/llama_parse/base.py#line=310), in LlamaParse.aload_data(self, file_path, extra_info)
    309 """Load data from the input path."""
    310 if isinstance(file_path, (str, Path)):
--> 311     return await self._aload_data(file_path, extra_info=extra_info)
    312 elif isinstance(file_path, list):
    313     jobs = [self._aload_data(f, extra_info=extra_info) for f in file_path]

File [~\venv\py311_llama_index\Lib\site-packages\llama_parse\base.py:304](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/llama_parse/base.py#line=303), in LlamaParse._aload_data(self, file_path, extra_info)
    302 except Exception as e:
    303     print(f"Error while parsing the file '{file_path}':", e)
--> 304     raise e
    305     return []

File [~\venv\py311_llama_index\Lib\site-packages\llama_parse\base.py:289](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/llama_parse/base.py#line=288), in LlamaParse._aload_data(self, file_path, extra_info)
    287 """Load data from the input path."""
    288 try:
--> 289     job_id = await self._create_job(file_path, extra_info=extra_info)
    290     if self.verbose:
    291         print("Started parsing the file under job_id %s" % job_id)

File [~\venv\py311_llama_index\Lib\site-packages\llama_parse\base.py:249](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/llama_parse/base.py#line=248), in LlamaParse._create_job(self, file_path, extra_info)
    247 url = f"{self.base_url}/api/parsing/upload"
    248 async with httpx.AsyncClient(timeout=self.max_timeout) as client:
--> 249     response = await client.post(url, files=files, headers=headers, data={"language": self.language.value, "parsing_instruction": self.parsing_instruction})
    250     if not response.is_success:
    251         raise Exception(f"Failed to parse the file: {response.text}")

File [~\venv\py311_llama_index\Lib\site-packages\httpx\_client.py:1892](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpx/_client.py#line=1891), in AsyncClient.post(self, url, content, data, files, json, params, headers, cookies, auth, follow_redirects, timeout, extensions)
   1871 async def post(
   1872     self,
   1873     url: URLTypes,
   (...)
   1885     extensions: RequestExtensions | None = None,
   1886 ) -> Response:
   1887     """
   1888     Send a `POST` request.
   1889 
   1890     **Parameters**: See `httpx.request`.
   1891     """
-> 1892     return await self.request(
   1893         "POST",
   1894         url,
   1895         content=content,
   1896         data=data,
   1897         files=files,
   1898         json=json,
   1899         params=params,
   1900         headers=headers,
   1901         cookies=cookies,
   1902         auth=auth,
   1903         follow_redirects=follow_redirects,
   1904         timeout=timeout,
   1905         extensions=extensions,
   1906     )

File [~\venv\py311_llama_index\Lib\site-packages\httpx\_client.py:1574](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpx/_client.py#line=1573), in AsyncClient.request(self, method, url, content, data, files, json, params, headers, cookies, auth, follow_redirects, timeout, extensions)
   1559     warnings.warn(message, DeprecationWarning)
   1561 request = self.build_request(
   1562     method=method,
   1563     url=url,
   (...)
   1572     extensions=extensions,
   1573 )
-> 1574 return await self.send(request, auth=auth, follow_redirects=follow_redirects)

File [~\venv\py311_llama_index\Lib\site-packages\httpx\_client.py:1661](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpx/_client.py#line=1660), in AsyncClient.send(self, request, stream, auth, follow_redirects)
   1653 follow_redirects = (
   1654     self.follow_redirects
   1655     if isinstance(follow_redirects, UseClientDefault)
   1656     else follow_redirects
   1657 )
   1659 auth = self._build_request_auth(request, auth)
-> 1661 response = await self._send_handling_auth(
   1662     request,
   1663     auth=auth,
   1664     follow_redirects=follow_redirects,
   1665     history=[],
   1666 )
   1667 try:
   1668     if not stream:

File [~\venv\py311_llama_index\Lib\site-packages\httpx\_client.py:1689](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpx/_client.py#line=1688), in AsyncClient._send_handling_auth(self, request, auth, follow_redirects, history)
   1686 request = await auth_flow.__anext__()
   1688 while True:
-> 1689     response = await self._send_handling_redirects(
   1690         request,
   1691         follow_redirects=follow_redirects,
   1692         history=history,
   1693     )
   1694     try:
   1695         try:

File [~\venv\py311_llama_index\Lib\site-packages\httpx\_client.py:1726](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpx/_client.py#line=1725), in AsyncClient._send_handling_redirects(self, request, follow_redirects, history)
   1723 for hook in self._event_hooks["request"]:
   1724     await hook(request)
-> 1726 response = await self._send_single_request(request)
   1727 try:
   1728     for hook in self._event_hooks["response"]:

File [~\venv\py311_llama_index\Lib\site-packages\httpx\_client.py:1763](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpx/_client.py#line=1762), in AsyncClient._send_single_request(self, request)
   1758     raise RuntimeError(
   1759         "Attempted to send an sync request with an AsyncClient instance."
   1760     )
   1762 with request_context(request=request):
-> 1763     response = await transport.handle_async_request(request)
   1765 assert isinstance(response.stream, AsyncByteStream)
   1766 response.request = request

File [~\venv\py311_llama_index\Lib\site-packages\httpx\_transports\default.py:373](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpx/_transports/default.py#line=372), in AsyncHTTPTransport.handle_async_request(self, request)
    360 req = httpcore.Request(
    361     method=request.method,
    362     url=httpcore.URL(
   (...)
    370     extensions=request.extensions,
    371 )
    372 with map_httpcore_exceptions():
--> 373     resp = await self._pool.handle_async_request(req)
    375 assert isinstance(resp.stream, typing.AsyncIterable)
    377 return Response(
    378     status_code=resp.status,
    379     headers=resp.headers,
    380     stream=AsyncResponseStream(resp.stream),
    381     extensions=resp.extensions,
    382 )

File [~\venv\py311_llama_index\Lib\site-packages\httpcore\_async\connection_pool.py:216](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpcore/_async/connection_pool.py#line=215), in AsyncConnectionPool.handle_async_request(self, request)
    213         closing = self._assign_requests_to_connections()
    215     await self._close_connections(closing)
--> 216     raise exc from None
    218 # Return the response. Note that in this case we still have to manage
    219 # the point at which the response is closed.
    220 assert isinstance(response.stream, AsyncIterable)

File [~\venv\py311_llama_index\Lib\site-packages\httpcore\_async\connection_pool.py:196](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpcore/_async/connection_pool.py#line=195), in AsyncConnectionPool.handle_async_request(self, request)
    192 connection = await pool_request.wait_for_connection(timeout=timeout)
    194 try:
    195     # Send the request on the assigned connection.
--> 196     response = await connection.handle_async_request(
    197         pool_request.request
    198     )
    199 except ConnectionNotAvailable:
    200     # In some cases a connection may initially be available to
    201     # handle a request, but then become unavailable.
    202     #
    203     # In this case we clear the connection and try again.
    204     pool_request.clear_connection()

File [~\venv\py311_llama_index\Lib\site-packages\httpcore\_async\connection.py:99](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpcore/_async/connection.py#line=98), in AsyncHTTPConnection.handle_async_request(self, request)
     97 except BaseException as exc:
     98     self._connect_failed = True
---> 99     raise exc
    101 return await self._connection.handle_async_request(request)

File [~\venv\py311_llama_index\Lib\site-packages\httpcore\_async\connection.py:76](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpcore/_async/connection.py#line=75), in AsyncHTTPConnection.handle_async_request(self, request)
     74 async with self._request_lock:
     75     if self._connection is None:
---> 76         stream = await self._connect(request)
     78         ssl_object = stream.get_extra_info("ssl_object")
     79         http2_negotiated = (
     80             ssl_object is not None
     81             and ssl_object.selected_alpn_protocol() == "h2"
     82         )

File [~\venv\py311_llama_index\Lib\site-packages\httpcore\_async\connection.py:154](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpcore/_async/connection.py#line=153), in AsyncHTTPConnection._connect(self, request)
    147     kwargs = {
    148         "ssl_context": ssl_context,
    149         "server_hostname": sni_hostname
    150         or self._origin.host.decode("ascii"),
    151         "timeout": timeout,
    152     }
    153     async with Trace("start_tls", logger, request, kwargs) as trace:
--> 154         stream = await stream.start_tls(**kwargs)
    155         trace.return_value = stream
    156 return stream

File [~\venv\py311_llama_index\Lib\site-packages\httpcore\_backends\anyio.py:80](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpcore/_backends/anyio.py#line=79), in AnyIOStream.start_tls(self, ssl_context, server_hostname, timeout)
     78     except Exception as exc:  # pragma: nocover
     79         await self.aclose()
---> 80         raise exc
     81 return AnyIOStream(ssl_stream)

File [~\venv\py311_llama_index\Lib\site-packages\httpcore\_backends\anyio.py:71](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/httpcore/_backends/anyio.py#line=70), in AnyIOStream.start_tls(self, ssl_context, server_hostname, timeout)
     69 try:
     70     with anyio.fail_after(timeout):
---> 71         ssl_stream = await anyio.streams.tls.TLSStream.wrap(
     72             self._stream,
     73             ssl_context=ssl_context,
     74             hostname=server_hostname,
     75             standard_compatible=False,
     76             server_side=False,
     77         )
     78 except Exception as exc:  # pragma: nocover
     79     await self.aclose()

File [~\venv\py311_llama_index\Lib\site-packages\anyio\streams\tls.py:132](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/anyio/streams/tls.py#line=131), in TLSStream.wrap(cls, transport_stream, server_side, hostname, ssl_context, standard_compatible)
    122 ssl_object = ssl_context.wrap_bio(
    123     bio_in, bio_out, server_side=server_side, server_hostname=hostname
    124 )
    125 wrapper = cls(
    126     transport_stream=transport_stream,
    127     standard_compatible=standard_compatible,
   (...)
    130     _write_bio=bio_out,
    131 )
--> 132 await wrapper._call_sslobject_method(ssl_object.do_handshake)
    133 return wrapper

File [~\venv\py311_llama_index\Lib\site-packages\anyio\streams\tls.py:140](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/venv/py311_llama_index/Lib/site-packages/anyio/streams/tls.py#line=139), in TLSStream._call_sslobject_method(self, func, *args)
    138 while True:
    139     try:
--> 140         result = func(*args)
    141     except ssl.SSLWantReadError:
    142         try:
    143             # Flush any pending writes first

File [~\AppData\Local\Programs\Python\Python311\Lib\ssl.py:979](http://localhost:8888/lab/tree/aa_Learn/LLM/model_Llama/llama_parse/Resources/official_examples/~/AppData/Local/Programs/Python/Python311/Lib/ssl.py#line=978), in SSLObject.do_handshake(self)
    977 def do_handshake(self):
    978     """Start the SSL/TLS handshake."""
--> 979     self._sslobj.do_handshake()

SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1006)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant