python - 属性错误: 'module' object has no attribute 'url'

标签 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
>>> 

最佳答案

这应该有效:

>>> 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/

相关文章:

python - django 表单 views.py - 错误 : inconsistent use of tabs and spaces in indentation

java - 无法测试服务器上部署的 Web 服务

rest - 是否可以在内部(私有(private))IIS 服务器上运行 Golang REST Web 应用程序?

java - 对 Jersey 休息服务的并发请求

python - 集成 CherryPy 网络框架、SQLAlchemy session 和 lighttpd 以提供高负载网络服务的最佳实践

python - 在 CherryPy 中使用映射

jquery - 如何使跨源资源共享 (CORS) 发布请求正常工作

Python OrderedDict : sort by tuple order?

python - 警告 : Incorrect Integer Value error MYSQL

python - keras 模型中损失函数的奇怪行为,具有预训练的卷积基