Decorater task ssl error

Hello
I am conducting cloud practice while looking at the perfect 2.0 document.

After I define a function using a decoder task, when I put the task function in the flow decoder function and run the file, problems with ssl occur in the cmd window.

So I turned the task decoder into a flow decoder and ran the file as a subflow, which doesn’t cause the same phenomenon.

Below are the code and the error statement that occurred.

from prefect import flow, task

@task
def create_message():
    msg = "hello"
    return (msg)

@flow
def something_else():
    result = 10
    return (result)

@flow
def hello():
    sub_flow_message = something_else()
    task_message = create_message()
    new_message = task_message + str(sub_flow_message)
    print(new_message)
    
if __name__ == "__main__":
    hello()

===========================================
19:44:27.796 | INFO | prefect.engine - Created flow run ‘tireless-curassow’ for flow ‘hello’
19:44:27.797 | INFO | Flow run ‘tireless-curassow’ - View at Prefect Cloud
19:44:30.118 | INFO | Flow run ‘tireless-curassow’ - Created subflow run ‘fuzzy-taipan’ for flow ‘something-else’
19:44:30.120 | INFO | Flow run ‘fuzzy-taipan’ - View at Prefect Cloud
19:44:31.141 | INFO | Flow run ‘fuzzy-taipan’ - Finished in state Completed()
19:44:31.448 | INFO | Flow run ‘tireless-curassow’ - Created task run ‘create_message-0’ for task ‘create_message’
19:44:31.450 | INFO | Flow run ‘tireless-curassow’ - Executing ‘create_message-0’ immediately…
19:44:31.778 | ERROR | GlobalEventLoopThread | prefect._internal.concurrency - Service ‘EventsWorker’ failed with 1 pending items.
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/_internal/concurrency/services.py”, line 118, in _run
async with self._lifespan():
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py”, line 199, in aenter
return await anext(self.gen)
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/worker.py”, line 30, in _lifespan
async with self._client:
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/clients.py”, line 123, in aenter
await self._reconnect()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/clients.py”, line 141, in _reconnect
self._websocket = await self._connect.aenter()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 637, in aenter
return await self
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 655, in await_impl_timeout
return await self.await_impl()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 659, in await_impl
_transport, _protocol = await self._create_connection()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py”, line 1092, in create_connection
transport, protocol = await self._create_connection_transport(
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py”, line 1122, in _create_connection_transport
await waiter
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py”, line 534, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py”, line 188, in feed_ssldata
self._sslobj.do_handshake()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py”, line 975, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
19:44:32.082 | ERROR | GlobalEventLoopThread | prefect._internal.concurrency - Service ‘EventsWorker’ failed with 1 pending items.
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/_internal/concurrency/services.py”, line 118, in _run
async with self._lifespan():
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py”, line 199, in aenter
return await anext(self.gen)
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/worker.py”, line 30, in _lifespan
async with self._client:
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/clients.py”, line 123, in aenter
await self._reconnect()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/clients.py”, line 141, in _reconnect
self._websocket = await self._connect.aenter()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 637, in aenter
return await self
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 655, in await_impl_timeout
return await self.await_impl()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 659, in await_impl
_transport, _protocol = await self._create_connection()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py”, line 1092, in create_connection
transport, protocol = await self._create_connection_transport(
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py”, line 1122, in _create_connection_transport
await waiter
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py”, line 534, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py”, line 188, in feed_ssldata
self._sslobj.do_handshake()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py”, line 975, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
19:44:32.608 | INFO | Task run ‘create_message-0’ - Finished in state Completed()
hello10
19:44:32.632 | ERROR | GlobalEventLoopThread | prefect._internal.concurrency - Service ‘EventsWorker’ failed with 1 pending items.
Traceback (most recent call last):
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/_internal/concurrency/services.py”, line 118, in _run
async with self._lifespan():
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/contextlib.py”, line 199, in aenter
return await anext(self.gen)
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/worker.py”, line 30, in _lifespan
async with self._client:
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/clients.py”, line 123, in aenter
await self._reconnect()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/prefect/events/clients.py”, line 141, in _reconnect
self._websocket = await self._connect.aenter()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 637, in aenter
return await self
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 655, in await_impl_timeout
return await self.await_impl()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/websockets/legacy/client.py”, line 659, in await_impl
_transport, _protocol = await self._create_connection()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py”, line 1092, in create_connection
transport, protocol = await self._create_connection_transport(
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py”, line 1122, in _create_connection_transport
await waiter
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py”, line 534, in data_received
ssldata, appdata = self._sslpipe.feed_ssldata(data)
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/sslproto.py”, line 188, in feed_ssldata
self._sslobj.do_handshake()
File “/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py”, line 975, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)
19:44:32.881 | INFO | Flow run ‘tireless-curassow’ - Finished in state Completed(‘All states completed.’)

Hi! I’m having the same problem. Were you able to fix it?

Hi @shl961004 and @Rachel_Rosen - this usually has to do with a problem with a python installation itself, not so much related to prefect.

Could you try these resolutions? I can try and help you debug further if none of them work for you

The solution I solved was to go into the path where Python was installed and run the Install Certificates.command file, so I updated it with a new file, and there was no problem after that. Oh and I’m using Mac os

Thanks nate : )