socotecio / django-socio-grpc

gRPC for Django.
https://django-socio-grpc.readthedocs.io/
Apache License 2.0
100 stars 22 forks source link

Quickstart #148

Closed lahirujayathilake closed 1 year ago

lahirujayathilake commented 1 year ago

Hi All,

First of all, thank you all for your contributions and for bringing this project alive. I just started using the Project and as instructed I followed the documentation for Quickstart - https://socotecio.github.io/django-socio-grpc/#quickstart

When I follow the steps I'll be getting an error when I try to execute the command, python manage.py generateproto

This gives the following error,

Traceback (most recent call last):
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django/utils/module_loading.py", line 30, in import_string
    return cached_import(module_path, class_name)
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django/utils/module_loading.py", line 16, in cached_import
    return getattr(module, class_name)
AttributeError: module 'tutorial.urls' has no attribute 'grpc_handlers'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django_socio_grpc/settings.py", line 111, in import_from_string
    return import_string(val)
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django/utils/module_loading.py", line 32, in import_string
    raise ImportError(
ImportError: Module "tutorial.urls" does not define a "grpc_handlers" attribute/class

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<project-path>/tutorial/manage.py", line 22, in <module>
    main()
  File "<project-path>/tutorial/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django_socio_grpc/management/commands/generateproto.py", line 53, in handle
    grpc_settings.ROOT_HANDLERS_HOOK(None)
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django_socio_grpc/settings.py", line 156, in __getattr__
    val = perform_import(val, attr)
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django_socio_grpc/settings.py", line 94, in perform_import
    return import_from_string(
  File "<project-path>/tutorial/venv/lib/python3.10/site-packages/django_socio_grpc/settings.py", line 113, in import_from_string
    raise ImportError(
ImportError: Could not import 'tutorial.urls.grpc_handlers' for GRPC setting 'ROOT_HANDLERS_HOOK'. ImportError: Module "tutorial.urls" does not define a "grpc_handlers" attribute/class.

I saw the django-grpc-framework project (https://github.com/fengsp/django-grpc-framework) mention this in the README.md file.

urlpatterns = []
def grpc_handlers(server):
    demo_pb2_grpc.add_UserControllerServicer_to_server(UserService.as_servicer(), server)

but this has to have generated stub classes.

Can you guide me on thow to get the quickstart project up and running?

AMontagu commented 1 year ago

Hello @lahirujayathilake The published doc was not up to date because of mkdocs font rgpd policy. Just upgraded my mkdocs policy and published the latest change. You should have a complete quickstart on https://socotecio.github.io/django-socio-grpc/#quickstart

I close this issue. If you face other problem do not hesitate to ask us.

lahirujayathilake commented 1 year ago

Thanks, @AMontagu for the update. Yes, it solved that issue however, I'm getting the following error when python manage.py generateproto is executed

  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/lexer.py", line 478, in lex
    yield lexer.next_token(lexer_state, parser_state)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/lexer.py", line 398, in next_token
    raise UnexpectedCharacters(lex_state.text, line_ctr.char_pos, line_ctr.line, line_ctr.column,
lark.exceptions.UnexpectedCharacters: No terminal matches 'q' in the current parser context, at line 4 col 19

  optional string question_text = 1;
                  ^
Expected one of: 
        * EQUAL

Previous tokens: Token('FIELDNAME', 'string')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<project-url>/tutorial/manage.py", line 22, in <module>
    main()
  File "<project-url>/tutorial/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/django/core/management/base.py", line 448, in execute
    output = self.handle(*args, **options)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/django_socio_grpc/management/commands/generateproto.py", line 80, in handle
    protos_by_app = generator.get_protos_by_app()
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/django_socio_grpc/protobuf/generators.py", line 45, in get_protos_by_app
    self.current_existing_proto_data = self.parse_existing_proto_file(
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/django_socio_grpc/protobuf/generators.py", line 201, in parse_existing_proto_file
    proto_data = protoparser.serialize2json_from_file(existing_proto_path)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/protoparser/parser.py", line 362, in serialize2json_from_file
    return json.dumps(_recursive_to_dict(parse(data)))
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/protoparser/parser.py", line 322, in parse
    tree = parser.parse(data)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/lark.py", line 581, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/parser_frontends.py", line 106, in parse
    return self.parser.parse(stream, chosen_start, **kw)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 41, in parse
    return self.parser.parse(lexer, start)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 171, in parse
    return self.parse_from_state(parser_state)
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 188, in parse_from_state
    raise e
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/parsers/lalr_parser.py", line 178, in parse_from_state
    for token in state.lexer.lex(state):
  File "<project-url>/tutorial/venv/lib/python3.10/site-packages/lark/lexer.py", line 487, in lex
    raise UnexpectedToken(token, e.allowed, state=parser_state, token_history=[last_token], terminals_by_name=self.root_lexer.terminals_by_name)
lark.exceptions.UnexpectedToken: Unexpected token Token('CONSTANT', 'question_text') at line 4, column 19.
Expected one of: 
        * EQUAL
Previous tokens: [Token('FIELDNAME', 'string')]

Is there something I'm missing?

AMontagu commented 1 year ago

@lahirujayathilake Can you provide a minimal reproduction of this ?

But first you can try to delete all your protofile and try generate again. The rror look like you already have a proto file with a syntax we do not support.

AMontagu commented 1 year ago

Close due to inactivity