Skip to content

Flet 打包APK 成功但是,引用requests 之后异常 #2833

@ChinaGodzilla

Description

@ChinaGodzilla

I wrote a routine that did not include the requests package and packaged the APK so that it could run normally on Android. When I referenced the requests library and packaged the APK, an error was reported as shown below.

96930525-11ea-4021-964d-48879f1d3f98

python code:

`import time

import flet as ft
import requests
from bs4 import BeautifulSoup
Url_list = []

def Get_news():
Count = 0
Web_text = requests.get('https://news.china.com/domestic/?x4fc.html')
#print(Web_text.text)
soup = BeautifulSoup(Web_text.content.decode('utf8'), 'html.parser')
# 查找所有的标签
news_links = soup.find_all('a')

# 遍历每个<a>标签,输出链接和文本内容
for link in news_links:
    Count += 1
    href_value = link.get('href')
    news_text = link.text
    #print(f"Link: {href_value}, Text: {news_text}")
    if Count > 40:
        Url_list.append(news_text)

def main(page: ft.Page):
page.title = "疼殉新闻"
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.appbar = ft.AppBar(title=ft.Text('疼殉新闻'),center_title=True,color='white',bgcolor=ft.colors.BLUE)
page.navigation_bar = ft.NavigationBar(
destinations=[
ft.NavigationDestination(icon=ft.icons.HOME, label="首页"),
ft.NavigationDestination(icon=ft.icons.NAVIGATION, label="热点"),
ft.NavigationDestination(
icon=ft.icons.ACCOUNT_BOX,
selected_icon=ft.icons.BOOKMARK,
label="我的",
),
]
)

lv = ft.ListView(expand=True, spacing=10)
Get_news()

for i in Url_list:
    lv.controls.append(ft.Text(str(i)))

page.update()
page.add(lv

)

ft.app(main)`

Packaging command

flet build apk --verbose

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions