我试图通过使用MakeQuery(query string)
模块从Python传递字符串来调用下面的ctypes
函数。
当我从Python中调用它作为函数共享对象并带有Go中Works()
的硬编码参数时,它将起作用:
//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 {} {...}
根据一些网络教程,我需要将其转换为这样:
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)
但是由于某些字符串类型转换错误而无法使用
&{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}
如果有人能指出我将Python的字符串类型以某种方式转换为Go的方向,那将是一个很大的帮助。