0

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

我想要做的是将其部署为 web 服务并能够看到它的 wsdl (localhost/wsgi/ape.wsgi/?wsdl)。这可能吗?Ps 我是 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)
4

0 回答 0