AttributeError:'模块'对象没有属性' url'

时间:2014-09-17 13:54:01

标签: python web-services cherrypy

我正在尝试运行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
>>> 

2 个答案:

答案 0 :(得分:1)

这应该有效:

>>> import cherrypy
>>> cherrypy.url
<function url at 0xb6d8f80c>

确保您没有为脚本cherrypy.py命名。如果您这样做,将阻止导入cherrypy包。

重命名文件,并确保没有cherrypy.pyc文件。

答案 1 :(得分:0)

抱歉,我发现了问题。

如果使用

安装cherrypy,则无效
sudo apt-get install python-cherrypy

您已使用

安装了点子
sudo apt-get install python-pip 

然后

sudo pip install CherryPy