Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't generate python client #1785

Closed
mkuklik opened this issue Nov 1, 2020 · 4 comments
Closed

Can't generate python client #1785

mkuklik opened this issue Nov 1, 2020 · 4 comments

Comments

@mkuklik
Copy link

mkuklik commented Nov 1, 2020

🐛 Bug Report

Python client generation fails using grpio_tools.I am using a_bit_of_everything.proto from examples.

To Reproduce

  1. in the root directory of grpc-gateway I run
python` -m grpc_tools.protoc a_bit_of_everything.proto --python_out=./proto/ --grpc_python_out=./proto/ \
  	--proto_path `pwd`/examples/internal/proto/examplepb
  1. in python

import a_bit_of_everything_pb2

Expected behavior

Actual Behavior

When trying to import a_bit_of_everything_pb.py I get the following errors,

Traceback (most recent call last):
File "", line 1, in
File "/Users/mkuklik/tshub/grpc-gateway/a_bit_of_everything_pb2.py", line 20, in
from protoc_gen_openapiv2.options import annotations_pb2 as protoc__gen__openapiv2_dot_options_dot_annotations__pb2
File "/Users/mkuklik/tshub/grpc-gateway/protoc_gen_openapiv2/options/annotations_pb2.py", line 18, in
DESCRIPTOR = _descriptor.FileDescriptor(
File "/Users/mkuklik/tshub/grpc-gateway/examples/internal/proto/examplepb/.venv/lib/python3.8/site-packages/google/protobuf/descriptor.py", line 941, in new
return _message.default_pool.AddSerializedFile(serialized_pb)
TypeError: Couldn't build proto file into descriptor pool!
Invalid proto descriptor for file "annotations.proto":
protoc-gen-openapiv2/options/openapiv2.proto: Import "protoc-gen-openapiv2/options/openapiv2.proto" has not been loaded.
grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger: "grpc.gateway.protoc_gen_openapiv2.options.Swagger" seems to be defined in "openapiv2.proto", which is not imported by "annotations.proto". To use it here, please add the necessary import.
grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation: "grpc.gateway.protoc_gen_openapiv2.options.Operation" seems to be defined in "openapiv2.proto", which is not imported by "annotations.proto". To use it here, please add the necessary import.
grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema: "grpc.gateway.protoc_gen_openapiv2.options.Schema" seems to be defined in "openapiv2.proto", which is not imported by "annotations.proto". To use it here, please add the necessary import.
grpc.gateway.protoc_gen_openapiv2.options.openapiv2_tag: "grpc.gateway.protoc_gen_openapiv2.options.Tag" seems to be defined in "openapiv2.proto", which is not imported by "annotations.proto". To use it here, please add the necessary import.
grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field: "grpc.gateway.protoc_gen_openapiv2.options.JSONSchema" seems to be defined in "openapiv2.proto", which is not imported by "annotations.proto". To use it here, please add the necessary import.

Even if I generate code for protoc-gen-openapiv2/options/ and protoc-gen-openapiv2/options/openapiv2.proto
and place them in ./grpc/gateway/protoc_gen_openapiv2/options/

I still get:

Invalid proto descriptor for file "annotations.proto":
protoc-gen-openapiv2/options/openapiv2.proto: Import "protoc-gen-openapiv2/options/openapiv2.proto" has not been loaded.
grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger: "grpc.gateway.protoc_gen_openapiv2.options.Swagger" seems to be defined in "openapiv2.proto", which is not imported by "annotations.proto". To use it here, please add the necessary import.

Your Environment

System:
Darwin mbp-geum 19.6.0 Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

Python:
appier==1.20.5
cachetools==4.1.1
certifi==2020.6.20
chardet==3.0.4
google-api==0.1.12
google-api-core==1.23.0
google-auth==1.23.0
googleapis-common-protos==1.52.0
grpcio==1.33.2
grpcio-tools==1.33.2
idna==2.10
protobuf==3.13.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pytz==2020.1
requests==2.24.0
rsa==4.6
six==1.15.0
urllib3==1.25.11

@johanbrandhorst
Copy link
Collaborator

Hi! Sorry you're having trouble using the gateway. Unfortunately I have no experience generating protobuf files with python, and this is not an issue with the gateway itself. I recommend you find someone who has experience generating python protobuf files to help you.

@iamnoah
Copy link

iamnoah commented May 9, 2021

If anyone is looking for a package with the generated python code for protoc_gen_openapiv2.options, I've uploaded one to PyPi.

pip install grpc-gateway-protoc-gen-openapiv2

@jonathanve
Copy link

That's great @iamnoah

@samahali
Copy link

@iamnoah
sir, u mentioned here
Building
1 - Install go
2 - ./gen-openapi-proto.sh will generate the code from grpc-gateway.
3- python3 -m pip install --upgrade build && python3 -m build to build the package.
4- optional - setup PyPi credentials and python3 -m pip install --user --upgrade twine && python3 -m twine upload --repository pypi dist/*

I don't understand this file where should I find it "2 - ./gen-openapi-proto.sh will generate the code from grpc-gateway."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants