请求库与Pyinstaller冲突

2024-04-16 06:00:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用pyisntaller使用pyinstaller main.py --onefile命令从main.py生成了一个.exe文件。生成的.exe在显示these errors (I couldn't copy and paste them because the program crashes immediately after opening)后立即崩溃。我相信这些错误是由于使用了requests库造成的,因为我在scrapeCashAndAccount函数中使用了这个库,这个函数在inputAll函数中调用。如果我不调用函数scrapeCashAndAccount,则不会发生错误,并且.exe文件运行正常。 下面是scrapeCashAndAccount函数:

import requests     #requests info from websites
import functions
from bs4 import BeautifulSoup
session = requests.Session()    # create session
loginUrl = 'https://investopedia.com/simulator/portfolio/'

payload = {
    'username': 'my email',
    'password': 'my password'
}

authPage = session.get(loginUrl)    # get log in page #if you print(authPage), it will print response of the webpage
soup = BeautifulSoup(authPage.content, 'html.parser')       #soup is an object #you can print(soup) or print(soup.prettify()) to print the HTM code of the webpage

# get form
form = soup.find('form')

# get post url
postUrl = form['action']
session.post(postUrl, data=payload)     #post insted of get 

tradeUrl = 'https://investopedia.com/simulator/trade/tradestock.aspx'
page = session.get(tradeUrl)
soup = BeautifulSoup(page.content, 'html.parser')
valueAndCash = soup.find_all('td', class_='value num')                             
#Then irrelevant stuff

这里有什么问题