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

grpcio-tools protoc.main 给出“缺少输出指令”错误

grpcio-tools protoc.main 给出“缺少输出指令”错误

森林海 2022-05-24 15:56:44
我想用于protoc.main(...)在运行时生成 python gRPC 文件,如下所示。from grpc_tools import protocargs = "--proto_path=. --python_out=grpc --grpc_python_out=grpc alpha.proto"result = protoc.main(c)上面的代码给出了带有结果代码的“缺少输出指令”错误1。但是,下面的解决方法可以alpha.proto作为命令行 args 工作。这意味着alpha.proto文件很好。import subprocessresult = subprocess.call("python -m grpc_tools.protoc " + args, shell=True)可能的原因是 (1)protoc.main确实像下面的代码那样对每个字符进行编码,或者 (2) 在内部protoc.main错误地解析了参数路径。def main(command_arguments):    """Run the protocol buffer compiler with the given command-line arguments.  Args:    command_arguments: a list of strings representing command line arguments to        `protoc`.  """    command_arguments = [argument.encode() for argument in command_arguments]    return _protoc_compiler.run_main(command_arguments)如何protoc.main正确使用?
查看完整描述

2 回答

?
一只萌萌小番薯

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

如果您正在遵循 golang protobufs 的中等教程,请不要复制和粘贴

protoc --go_out=. *.proto

命令,因为--不是真实-的(破折号等),所以手动输入命令解决了我的问题。

由于复制和粘贴不正确的字符,我收到此错误

我希望你能从我的愚蠢错误中吸取教训:)


查看完整回答
反对 回复 2022-05-24
?
暮色呼如

TA贡献1853条经验 获得超9个赞

proto下面的代码将在文件所在的目录中生成 python 文件.proto。


proto_files = ["proto/file1.proto", "proto/file2.proto"]


from grpc_tools import protoc

for file in proto_files:

    grpc_tools.protoc.main([

        'grpc_tools.protoc',

        '--proto_path=.',

        '--python_out=.',

        '--grpc_python_out=.',

        file

    ])


查看完整回答
反对 回复 2022-05-24
  • 2 回答
  • 0 关注
  • 296 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

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

帮助反馈 APP下载

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

公众号

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