【发布时间】:2017-10-13 16:21:47
【问题描述】:
环境
・Python 3.6.0
・瓶子 0.13-dev
・mod_wsgi-4.5.15
在网络上尝试以下代码会导致 500 错误
500 内部服务器错误
应用程序/wsgi
# -*- coding:utf-8 -*-
import sys, os
dirpath = os.path.dirname(os.path.abspath(__file__))
sys.path.append(dirpath)
sys.path.append('../')
os.chdir(dirpath)
import bottle
import index
application = bottle.default_app()
index.py
from urllib.request import urlopen
from bs4 import BeautifulSoup
from bottle import route, view
@route('/')
@view("index_template")
def index():
html = urlopen("https://en.wikipedia.org/wiki/Kevin_Bacon")
internalLinks=[]
bsObj = BeautifulSoup(html, "html.parser")
for link in bsObj.findAll("a"):
if 'href' in links.attr:
internalLinks.append(links.attr['href'])
return dict(internalLinks=internalLinks)
views/index_template.tpl
{{internalLinks}}
apache 日志
[error] mod_wsgi (pid=23613): Target WSGI script '/app.wsgi' cannot be loaded as Python module.
[error] mod_wsgi (pid=23613): Exception occurred processing WSGI script '/app.wsgi'.
[error] Traceback (most recent call last):
[error] File "/app.wsgi", line 8, in <module>
[error] import index
[error] File "/index.py", line 11
[error] for link in bsObj.findAll("a"):
[error] ^
[error] IndentationError: unexpected indent
【问题讨论】:
标签: python python-3.x beautifulsoup bottle