TabPy TypeError%d format需要一个数字,而不是str,后面没有返回值

2024-09-30 16:33:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚开始在10.13.2和Tabby合作。我使用conda pymysql包(pymysql和pymysql-0.8.0-py2.7.egg info)并将它们放在anaconda的site包中,这样Tableau就可以连接到数据库,检索数据集并保存在计算字段中。在

我最初试过了mysql.connector,就像我在PyCharm和CLI中所做的那样,但是TabPy使用anaconda,它没有mysql的站点包。在

无论如何,它最初连接到TabPy服务器,它返回:

An error occurred while communicating with the Predictive Service.

然而,接下来的两行很快就会出现:

^{pr2}$

我已经对上述错误做了一些挖掘,我所尝试的一切都产生了同样的错误。我找到了解决办法,但最后又有一个错误。在

SCRIPT_REAL("
import pymysql

db = pymysql.connect(
                     host='localhost',
                     port='9999',
                     user='usern',
                     passwd='passw',
                     db='someDb'
                     )

cur = db.cursor()

t1 = int(0)

t2 = datetime.datetime(2018, 2, 1)

sqlStr = 'select distinct APPL_ID, APPL_SUBMIT_DT from APPL_APP where APPL_ACTIVE_FLAG > %d and APPL_SUBMIT_DT >= %d' % (t1, t2)

cur.execute()

for row in cur.fetchall():
    print row

db.close()
",
COUNT([Appl Id])
)

我不明白为什么脚本会返回这样一个错误,直到我在PyCharm中运行它。我的端口号需要是数字而不是字符串。在

import pymysql

db = pymysql.connect(
                     host='localhost',
                     port=9999,
                     user='usern',
                     passwd='passw',
                     db='someDb'
                     )

cur = db.cursor()

t1 = int(0)

t2 = (2018-02-01)

sqlStr = 'select distinct APPL_ID, APPL_SUBMIT_DT from APPL_APP where APPL_ACTIVE_FLAG > %d and APPL_SUBMIT_DT >= %d' % (t1, t2)

cur.execute(sqlStr)

for row in cur.fetchall():
    print row

db.close()

当然,虽然我可以看到通过TabPy服务器在终端中返回的所有数据,但它完成了以下工作:

(3957423, datetime.datetime(2018, 2, 27, 15, 30, 16))
(3957424, datetime.datetime(2018, 2, 27, 15, 31))
(3957425, datetime.datetime(2018, 2, 27, 15, 31, 4))
(3957426, datetime.datetime(2018, 2, 27, 15, 31, 55))
(3957428, datetime.datetime(2018, 2, 27, 15, 32, 17))
(3957429, datetime.datetime(2018, 2, 27, 15, 32, 18))
None
ERROR:__main__:{"info": null, "ERROR": "Error running script. No return value"}

怎么可能?那里显然有数据。在


Tags: 数据infodbdatetime错误dtrowsubmit
1条回答
网友
1楼 · 发布于 2024-09-30 16:33:12

为了让脚本在Tableau中工作,您需要使用python命令return something,其中something是一个包含适当返回类型的列表。否则这些值可能存在于python中,但是Tableau看不到它们。在

在这种情况下,您需要使用如下代码构建一个列表:

ReturnValues=[]
for row in cur.fetchall():
   ReturnValues.append(row)
return ReturnValues

然后,完整的行列表将被发送回Tableau。但是,您可能仍然有问题,因为Tableau需要一个特定大小的列表,该列表与发送给python的输入列表相匹配。你没有这样一个可能导致问题的输入。在

相关问题 更多 >