我使用flask创建了一个网站,它接收字符串,根据字符串创建url,解析url,然后将其反馈给网站。我创建了一个函数来实现这一点,它工作得非常完美。然而,当我在flask程序中实现它时,它开始抛出一个运行时错误,其中指出:
服务器上发生应用程序错误。此应用程序的当前自定义错误设置阻止远程查看应用程序错误的详细信息(出于安全原因)。然而,它可以被运行在本地服务器机器上的浏览器查看。
详细信息:要在远程计算机上查看此特定错误消息的详细信息,请在位于当前web应用程序根目录中的“web.config”配置文件中创建customErrors标记。然后,此customErrors标记的“mode”属性应设置为“Off”。
我不熟悉创建web。配置或如何在我的flask程序中实现。任何帮助都将不胜感激。
代码:
单独运行时工作的函数:
def parse_wotc():
set_list = []
# Manually enter in value for test
card_url = 'http://gatherer.wizards.com/Pages/Card/Details.aspx?name=' +
'mountain' # (replace mountain) card_name.replace(' ', '+')
soup = BeautifulSoup(requests.get(card_url).text, 'html.parser')
for image in soup.find_all('img'):
if image.get('title') is not None:
set_list.append(image.get('title'))
print(set_list)
return set_list
webapp代码:
@app.route('/', methods=['GET', 'POST'])
def index():
card_name = None
card_url = '/static/images/card_back.jpg'
if request.form.get('random_button'):
card_url, card_name = random_card_image(list_card_names)
# When function ran here it give the error
parse_wotc(card_name)
def random_card_image(list_card_names):
"""This function will pull a random card name from the provided list and
return to main program"""
card_name = random.choice(list_card_names)
card_url = 'http://gatherer.wizards.com/Handlers/Image.ashx?name=' +
card_name.replace(' ', '+').lower() + \
'&type=card'
return card_url, card_name