Nik*_*as9 4 python apache django mod-python beautifulsoup
我正在尝试使用Django中的BeautifulSoup版本4(使用带有mod_python的Apache2)动态呈现HTML页面.但是,只要我将任何HTML字符串传递给BeautifulSoup构造函数(请参阅下面的代码),浏览器就会挂起等待Web服务器.我在CLI中尝试了相同的代码,它就像一个魅力.所以我猜它是与BeautifulSoups环境相关的东西,在这种情况下是Django + Apache + mod_python.
import bs4
import django.shortcuts as shortcuts
def test(request):
s = bs4.BeautifulSoup('<b>asdf</b>')
return shortcuts.render_to_response('test.html', {})
Run Code Online (Sandbox Code Playgroud)
我用pip安装了BeautifulSoup pip install beautifulsoup4.我尝试使用标准的Debian软件包安装BeautifulSoup3 apt-get install python-beautifulsoup,然后以下等效代码工作正常(来自浏览器和CLI).
from BeautifulSoup import BeautifulSoup
import django.shortcuts as shortcuts
def test(request):
s = BeautifulSoup('<b>asdf</b>')
return shortcuts.render_to_response('test.html', {})
Run Code Online (Sandbox Code Playgroud)
我查看了Apaches访问和错误日志,它们没有显示发生停顿的请求的信息.我还检查了/ var/log/syslog和/ var/log/messages,但没有进一步的信息.
这是我使用的Apache配置:
<VirtualHost *:80>
DocumentRoot /home/nandersson/src
<Directory /home/nandersson/src>
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE app.settings
PythonOption django.root /home/nandersson/src
PythonDebug On
PythonPath "['/home/nandersson/src'] + sys.path"
</Directory>
<Location "/media/">
SetHandler None
</Location>
<Location "/app/poc/">
SetHandler None
</Location>
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
我不确定如何进一步调试,不确定它是否是一个bug.任何人都有关于如何深入了解或遇到类似问题的想法?
小智 15
我正在使用带有mod_python的Apache2.我通过显式传递'html.parser'来解决挂起问题.
s = bs4.BeautifulSoup('<b>asdf</b>', 'html.parser')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1017 次 |
| 最近记录: |