我正在尝试运行 dripls当我安装包括 Fabric、apache2 在内的所有内容并设置适当的配置文件时
我遇到以下问题
AttributeError: 'module' object has no attribute 'url'
来自包 cherrypy
在这一行
app = {
'root_url': cherrypy.url()
}
谁能指出可能是什么问题吗?
**更新:**
有问题的脚本(完整)
import cherrypy
import urlparse
import uuid
import os
# Service
socket = '0.0.0.0'
dripls_main_site_port = 8080
thread_pool = 10
bin_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))), "bin")
pidfile = os.path.join(bin_path, "dripls.pid")
error_log = os.path.join(bin_path, "error_log.log")
access_log = os.path.join(bin_path, "access_log.log")
app = {
'root_url': cherrypy.url()
}
# Shaper path
shaper_path = os.path.join(bin_path, "set_ts_lo.sh")
# Shape port range
shape_start_port = 10000
shape_end_port = 11000
# Environment overrides
if os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "env.py")):
from env import *
else:
from local import *
port = int(dripls_main_site_port)
# Final url rewrite. Hack to battle the fact that cherrypy is behind a proxy on different port
def get_final_url(path, args):
cherrypy_url = cherrypy.url(path, args)
scheme, netloc, path, qs, anchor = urlparse.urlsplit(cherrypy_url)
return urlparse.urlunsplit( (scheme, urlparse.urlsplit(app['root_url'])[1], path, qs, anchor))
def get_seeded_cid(cid):
return "{0}_{1}".format(cid, uuid.uuid4().hex)"
更新:
Python 2.7.3 (default, Apr 10 2013, 05:46:21)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cherrypy
>>> cherrypy.url
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'url'
>>> print cherrypy.__file__
/usr/lib/pymodules/python2.7/cherrypy/__init__.pyc
>>>
最佳答案
这应该有效:
>>> import cherrypy
>>> cherrypy.url
<function url at 0xb6d8f80c>
确保您没有将脚本命名为 cherrypy.py
。如果这样做,它将阻止导入 cherrypy
包。
重命名该文件,并确保没有剩余 cherrypy.pyc
文件。
关于python - 属性错误: 'module' object has no attribute 'url' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25892555/