Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用apache2部署soaplib webservice_Python_Web Services_Apache_Mod Wsgi_Soaplib - Fatal编程技术网

Python 使用apache2部署soaplib webservice

Python 使用apache2部署soaplib webservice,python,web-services,apache,mod-wsgi,soaplib,Python,Web Services,Apache,Mod Wsgi,Soaplib,我已经建立了apache2和mod_wsgi。我有一个wsgi目录,其中有一些python代码保存在*.wsgi文件中。代码粘贴在下面。在web浏览器中,当我输入url(localhost/wsgi/ape.wsgi)时,它会将从数据库返回的记录显示为连接字符串 我试图做的是将其部署为Web服务,并能够查看其wsdl(localhost/wsgi/ape.wsgi/?wsdl)。这可能吗?另外,我是Python的新手。谢谢 import sys sys.stdout = sys.stderr

我已经建立了apache2和mod_wsgi。我有一个wsgi目录,其中有一些python代码保存在*.wsgi文件中。代码粘贴在下面。在web浏览器中,当我输入url(localhost/wsgi/ape.wsgi)时,它会将从数据库返回的记录显示为连接字符串

我试图做的是将其部署为Web服务,并能够查看其wsdl(localhost/wsgi/ape.wsgi/?wsdl)。这可能吗?另外,我是Python的新手。谢谢

import sys
sys.stdout = sys.stderr

import atexit
import threading
import cherrypy

from soaplib.wsgi_soap import SimpleWSGISoapApp
from soaplib.service import soapmethod
from soaplib.serializers.primitive import*

cherrypy.config.update({'environment': 'embedded'})

if cherrypy.__version__.startswith('3.0') and cherrypy.engine.state == 0:
    cherrypy.engine.start(blocking=False)
    atexit.register(cherrypy.engine.stop)


class Root(SimpleWSGISoapApp):
    @soapmethod(_returns=String)
    def index(self):
        """Get the data from the database and return list of rows"""
        cursor = self._get_db_handle()

        sql = """select name, source_comment from public.carpark where public_toilet = %s """ % 'TRUE'
        results = []
        cursor.execute(sql)
        rows=cursor.fetchall()

        for row in rows:
            results.append(str(row))

        joinedlist = ', '.join(results)
        return joinedlist
        cursor.close()


    def _get_db_handle(self, host='xxxx.xxxx.com',
               dbname='xxxx',user='xxxx',
               password='xxxx',mapped=False):
        """Get the database handle"""
        import psycopg2
        from psycopg2 import extras
        conn = psycopg2.connect("dbname='%s' user='%s' host='%s' password='%s'" % (dbname,user,host,password))
        if not mapped:
            db_handle = conn.cursor()
        else:
            db_handle = conn.cursor(cursor_factory=extras.DictCursor)
        return db_handle

    index.exposed = True

application = cherrypy.Application(Root(), script_name=None, config=None)

那么,实际问题是什么?你真的没说。你读过关于如何在mod_wsgi下部署的CherryPy文档吗?我真的不知道如何正确配置它。我希望能够使用类似以下URL的URL调用Web服务:。我尝试在脚本底部添加以下行:application=cherrypy.application(Root(),script\u name=None,config=None)。但是我无法打开这一页。请原谅我的无知,但我正在学习python。请使用您使用的mod_wsgi配置修改您的问题,您将wsgi脚本文件和实际收到的错误消息放在浏览器和/或Apache错误日志文件中。我已在帖子中更新了代码。当我在浏览器()中输入url时,它会显示一个从数据库返回的记录字符串。我想将其公开为Web服务。我该怎么做呢?所以现在不是部署问题,也不是应用程序的编码问题。我帮不了你。