gloabl name cx未定义

时间:2016-08-02 09:38:22

标签: python web.py cx-oracle

我想使用cx_Oracle的cursor.callfunc()调用Oracle函数返回一个对象。但这不起作用

在这里你可以看到我的代码:

import cx_Oracle
import json
import web

urls = (
"/", "index",
"/grid", "grid",
)
app = web.application(urls, globals(),web.profiler )
web.config.debug = True

connection = cx_Oracle.Connection("TEST_3D/limo1013@10.40.33.160:1521/sdetest")
typeObj = connection.gettype("MDSYS.SDO_GEOMETRY")

class index:
    def GET(self):
        return "hallo moritz " 

class grid:

    def GET(self):
        web.header('Access-Control-Allow-Origin',      '*')
        web.header('Access-Control-Allow-Credentials', 'true')      
        web.header('Content-Type', 'application/json')

        cursor = connection.cursor()
        cursor.arraysize = 10000 # default = 50
        cursor.execute("""SELECT a.id AS building_nr, c.Geometry AS geometry, d.Classname FROM   building a, THEMATIC_SURFACE b, SURFACE_GEOMETRY c, OBJECTCLASS d  WHERE  a.grid_id_400 = 4158 AND a.id = b.BUILDING_ID AND b.LOD2_MULTI_SURFACE_ID = c.ROOT_ID AND c.GEOMETRY IS NOT NULL AND b.OBJECTCLASS_ID = d.ID""")

        obj = cursor.fetchone()
        obj = obj[1]
        print obj

        cursor.callfunc("SDO2GEOJSON", cx.Oracle.OBJECT, [obj])

# Aufruf der App        
if __name__ == "__main__": 
        app.run(web.profiler)

错误讯息: at / grid 全局名称'cx'未定义

但我确信cx_Oracle安装正确。此外,我在开头使用import cx_Oracle,这是有效的。

有什么问题?

1 个答案:

答案 0 :(得分:1)

简单的拼写错误。在行

cursor.callfunc("SDO2GEOJSON", cx.Oracle.OBJECT, [obj])

您应该使用cx_Oracle.OBJECT

相关问题