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

Apply Python SSL fix when packaging for iOS and Android #2349

Closed
1 task done
FeodorFitsner opened this issue Jan 8, 2024 Discussed in #2312 · 0 comments
Closed
1 task done

Apply Python SSL fix when packaging for iOS and Android #2349

FeodorFitsner opened this issue Jan 8, 2024 Discussed in #2312 · 0 comments
Assignees
Labels
enhancement Improvement/Optimization packaging Related to app packaging

Comments

@FeodorFitsner
Copy link
Contributor

Discussed in #2312

Originally posted by fsmosca January 4, 2024

Question

I built an android sample todo app using flet build apk, see also the full codes in the Code sample section. The App just takes an input from the users and save it in Detabase in Deta space cloud.

This setup worked in windows 10 without issues.

image

I have three files namely: .env, requirements.txt and main.py.

In my android device Samsung Galaxy A14 with latest update installed, I got this error message:

[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)

This is triggered in the following code, when I try to fetch entries in the Detabase, and is captured by the SnackBar.

    def build_table_cells(db):
        """Gets entries from detabase."""
        try:
            response = db.fetch()
        except Exception as err:
            page.snack_bar = ft.SnackBar(
                content=ft.Text(f'error message: {err}'),
                action="Alright!",
                duration=10000,
            )
            page.snack_bar.open = True
            page.update()
        else:
            return [ft.DataRow(cells=[ft.DataCell(ft.Text(v['task']))]) for v in response.items]
        return []

Does this issue related to my device, or deta space or from the flet's built apk?

Code sample

.env

DATA_KEY = 'XXXXXXXX'

requirements.txt

flet
deta
python-dotenv

main.py

import os

import flet as ft
from deta import Deta
from dotenv import load_dotenv


load_dotenv()


def main(page: ft.Page):
    # Initialize deta
    deta = Deta(os.getenv('DATA_KEY'))
    db = deta.Base("todo_db")

    def get_data_key(e):
        """Show data key."""
        page.snack_bar = ft.SnackBar(
            content=ft.Text(os.getenv('DATA_KEY')),
            action="Alright!",
            duration=5000,
        )
        page.snack_bar.open = True
        page.update()

    def add_task(e):
        """Adds task from user input."""
        page.add(ft.Checkbox(label=new_task.value))

        # Update detabase and table.
        try:
            db.put({"task": new_task.value})
        except Exception as err:
            page.snack_bar = ft.SnackBar(
                content=ft.Text(f'error message: {err}'),
                action="Alright!",
                duration=10000,
            )
            page.snack_bar.open = True
            page.update()
        else:
            dcell = build_table_cells(db)
            table.rows = dcell

        new_task.value = ""
        page.update()

    def build_table_cells(db):
        """Gets entries from detabase."""
        try:
            response = db.fetch()
        except Exception as err:
            page.snack_bar = ft.SnackBar(
                content=ft.Text(f'error message: {err}'),
                action="Alright!",
                duration=10000,
            )
            page.snack_bar.open = True
            page.update()
        else:
            return [ft.DataRow(cells=[ft.DataCell(ft.Text(v['task']))]) for v in response.items]
        return []
    
    # Init table.
    table = ft.DataTable(
        columns=[
            ft.DataColumn(ft.Text("Task")),
        ]
    )

    # Add data cells in table from detabase.
    dcell = build_table_cells(db)
    table.rows = dcell

    new_task = ft.TextField(hint_text="Whats needs to be done?")

    # Build the UI
    page.add(
        ft.Column(
            controls=[
                ft.ElevatedButton("Query Deta Key", on_click=get_data_key),
                ft.Row(
                    controls=[
                        new_task,
                        ft.FloatingActionButton(icon=ft.icons.ADD, on_click=add_task)
                    ]
                ),
                ft.Text('Task List', weight=ft.FontWeight.BOLD),  # table header
                ft.Column(
                    controls=[                        
                        table
                    ],
                    scroll=ft.ScrollMode.ADAPTIVE,
                    height=200
                )
            ]
        )
    )


ft.app(target=main)


### Error message

```bash
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)

------------------------------------------------------

  • I have searched for answers to my question both in the issues and in previous discussions.
@FeodorFitsner FeodorFitsner added the enhancement Improvement/Optimization label Jan 8, 2024
@FeodorFitsner FeodorFitsner self-assigned this Jan 8, 2024
@FeodorFitsner FeodorFitsner added the packaging Related to app packaging label Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement/Optimization packaging Related to app packaging
Projects
Archived in project
Development

No branches or pull requests

1 participant