duanmao1975 2019-05-18 12:59
浏览 91

将字符串作为参数从Python传递到共享库中的Go函数

I'm trying to call the below MakeQuery(query string) function by passing the string from Python using ctypes module.

It works when I call it from Python as a function shared object with hardcoded arguments from Works() in Go:

//export Works
func Works() {
    newMod := MakeQuery(`SELECT TOP 3 NodeID FROM NCM.ConfigArchive`)
    fmt.Println(newMod)
}

// Query db connection and return results as map
//export MakeQuery
func MakeQuery(query string) []map[string]interface {} {...}

According to some web tutorials, I need to convert it as such:

from ctypes import *

lib = cdll.LoadLibrary("./test.so")
query = "SELECT TOP 3 NodeID FROM NCM.ConfigArchive"
b_query = query.encode('utf-8')
lib.MakeQuery.argtypes = [c_char_p]
print lib.MakeQuery(b_query)

But it doesn't work due to some string type conversion error:

&{400 Bad Request 400 HTTP/1.1 1 1 map[Content-Length:[1602] Content-Type:
[application/json] Date:[Sat, 18 May 2019 12:48:54 GMT] Server:[Microsoft-
HTTPAPI/2.0]] 0xc00009a1c0 1602 [] false false map[] 0xc000104000 0xc0001a8000}

Would be a great help if someone can point me to the direction to convert Python's string type into Go in some way.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?