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

zkg create fails with UnicodeEncodeError when using non-ASCII characters in user vars #193

Open
AmazingPP opened this issue Jun 27, 2024 · 0 comments · May be fixed by #194
Open

zkg create fails with UnicodeEncodeError when using non-ASCII characters in user vars #193

AmazingPP opened this issue Jun 27, 2024 · 0 comments · May be fixed by #194

Comments

@AmazingPP
Copy link

AmazingPP commented Jun 27, 2024

Description:

When attempting to create a package using zkg create, I encountered an issue where non-ASCII characters in the user variables (e.g., author name) result in a UnicodeEncodeError. This prevents the package creation from completing successfully

Steps to Reproduce:

  1. Run the following command:
zkg create --feature license --packagedir foo
  1. Provide the following inputs when prompted:
name: Foo
author: 张三 <xxxxxxx@gmail.com>
license: mit

Observed Output:

2024-06-27 17:36:44 ERROR    problem during template instantiation: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/zeek/6.2.1/bin/zkg", line 2295, in cmd_create
    package.do_instantiate(tmpl, args.packagedir, args.force)
  File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 708, in do_instantiate
    super().do_instantiate(tmpl, packagedir, use_force)
  File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 552, in do_instantiate
    self.instantiate(tmpl)
  File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 566, in instantiate
    for orig_file, path_name, file_name, content in self._walk(tmpl):
  File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 670, in _walk
    out_content = self._replace(tmpl, hdl.read())
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/zeek/6.2.1/lib/zeek/python/zeekpkg/template.py", line 692, in _replace
    val = bytes(val, "ascii")
          ^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)
error: problem during template instantiation: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

Expected Output:

The package should be created successfully, handling non-ASCII characters in the user inputs without errors.

Environment:

  • zkg version: 3.0.1
  • Zeek version: 6.2.1
  • Python version: 3.12.4
  • OS: macOS (using homebrew)

Additional Information:

The issue seems to stem from an attempt to encode non-ASCII characters using the ASCII codec, resulting in a UnicodeEncodeError.

Please consider updating the relevant code to handle non-ASCII characters.

@AmazingPP AmazingPP changed the title zkg create fails with UnicodeEncodeError when using non-ASCII characters in user vars zkg create fails with UnicodeEncodeError when using non-ASCII characters in user vars Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant