为了账号安全,请及时绑定邮箱和手机立即绑定

C.串() 仅返回第一个字符

C.串() 仅返回第一个字符

Go
沧海一幻觉 2022-10-04 18:52:04
我正在尝试使用c共享(.so)文件从Python调用Go函数。在我的python代码中,我调用的函数如下所示:website = "https://draftss.com"domain = "draftss.com"website_ip = "23.xxx.xxx.xxx"website_tech_finder_lib = cdll.LoadLibrary("website_tech_finder/builds/websiteTechFinder.so")result_json_string: str = website_tech_finder_lib.FetchAllData(website, domain, website_ip)在Go端,我正在根据这篇SO帖子将字符串转换为Go字符串(从共享库访问函数时内存不足):func FetchAllData(w *C.char, d *C.char, dIP *C.char) *C.char {    var website string = C.GoString(w)    var domain string = C.GoString(d)    var domainIP string = C.GoString(dIP)    fmt.Println(website)    fmt.Println(domain)    fmt.Println(domainIP)        .... // Rest of the code}网站域和 domainIP 只有我传递的字符串的第一个字符:fmt.Println(website)  // -> hfmt.Println(domain)   // -> dfmt.Println(domainIP) // -> 2我对Go有点陌生,所以我不确定我是否在这里做了一些愚蠢的事情。如何获取我传递的完整字符串?
查看完整描述

1 回答

?
元芳怎么了

TA贡献1798条经验 获得超7个赞

您需要将参数转换为 UTF8 字节。


website = "https://draftss.com".encode('utf-8')

domain = "draftss.com".encode('utf-8')

website_ip = "23.xxx.xxx.xxx".encode('utf-8')


lib = cdll.LoadLibrary("website_tech_finder/builds/websiteTechFinder.so")

result_json_string: str = website_tech_finder_lib.FetchAllData(website, domain, website_ip)


查看完整回答
反对 回复 2022-10-04
  • 1 回答
  • 0 关注
  • 125 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号