Skip to content

Android Flet App accessing Detabase in the cloud error message: [SSL: CERTIFICATE_VERIFY_FAILED] #2312

Answered by FeodorFitsner
fsmosca asked this question in Q&A
Discussion options

You must be logged in to vote

Add the following code to main.py of your Flet app to "fix" SSL issue on both iOS and Android:

import certifi
import os

os.environ["REQUESTS_CA_BUNDLE"] = certifi.where()
os.environ["SSL_CERT_FILE"] = certifi.where()

if os.getenv("FLET_PLATFORM") == "android":
    import ssl

    def create_default_context(
        purpose=ssl.Purpose.SERVER_AUTH, *, cafile=None, capath=None, cadata=None
    ):
        return ssl.create_default_context(
            purpose=purpose, cafile=certifi.where(), capath=capath, cadata=cadata
        )

    ssl._create_default_https_context = create_default_context

Hope that helps.

I'm going to document that.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@fsmosca
Comment options

@ingdesarr1
Comment options

Answer selected by fsmosca
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
docs Related to the documentation help wanted Extra attention is needed
3 participants