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

[BUG] babel TypeError: Unexpected value for identifier: None #53

Closed
Jackiexiao opened this issue Jun 4, 2023 · 4 comments
Closed

[BUG] babel TypeError: Unexpected value for identifier: None #53

Jackiexiao opened this issue Jun 4, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@Jackiexiao
Copy link

Plugin version

latest version

Python version

3.10

Additional environment information (optional)

No response

What happened?

File "/Users/jackiexiao/miniconda3/lib/python3.10/site-packages/mkdocs_blogging_plugin/util.py", line 150, in get_localized_date
return format_datetime(time, format="short", locale=_locale)
File "/Users/jackiexiao/miniconda3/lib/python3.10/site-packages/babel/dates.py", line 719, in format_datetime
locale = Locale.parse(locale)
File "/Users/jackiexiao/miniconda3/lib/python3.10/site-packages/babel/core.py", line 317, in parse
raise TypeError(f"Unexpected value for identifier: {identifier!r}")
TypeError: Unexpected value for identifier: None

What should have happened? (optional)

No response

How to reproduce the bug?

in macos

Python 3.10.10 (main, Mar 21 2023, 13:41:05) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> locale.getdefaultlocale()
(None, 'UTF-8')
>>>

so _locale get None which is wrong in mkdocs_blogging_plugin/util.py

    @staticmethod
    def get_localized_date(timestamp: float, day_only: bool, format: str=None, _locale: str=None) -> str:
        time = datetime.fromtimestamp(timestamp)
        if format:
            return datetime.strftime(time, format)
        else:
            if not _locale:
                _locale = locale.getdefaultlocale()[0]

Additional context (optional)

No response

Relevant log output (optional)

No response

@Jackiexiao Jackiexiao added the bug Something isn't working label Jun 4, 2023
@Jackiexiao Jackiexiao changed the title [BUG] [BUG] babel TypeError: Unexpected value for identifier: None Jun 4, 2023
@liang2kl
Copy link
Owner

liang2kl commented Jun 4, 2023

This has been fixed in #50, but I forgot to release a new version. The patch will be released soon.

@liang2kl
Copy link
Owner

liang2kl commented Jun 4, 2023

@liang2kl liang2kl closed this as completed Jun 4, 2023
@spipnl
Copy link

spipnl commented Jun 8, 2023

Hi, I'm using v2.2.9 and still have this error:

ERROR    -  Error reading page 'blog/test.md': Unexpected value for identifier: None
Traceback (most recent call last):
  File "/opt/homebrew/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/homebrew/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs/__main__.py", line 234, in serve_command
    serve.serve(dev_addr=dev_addr, livereload=livereload, watch=watch, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 83, in serve
    builder(config)
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs/commands/serve.py", line 76, in builder
    build(config, live_server=live_server, dirty=dirty)
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs/commands/build.py", line 308, in build
    _populate_page(file.page, config, files, dirty)
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs/commands/build.py", line 184, in _populate_page
    page.content = config.plugins.run_event(
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs/plugins.py", line 520, in run_event
    result = method(item, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs_blogging_plugin/plugin.py", line 275, in on_page_content
    self.with_timestamp(page, config.sort["by"] == "revision"))
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs_blogging_plugin/plugin.py", line 346, in with_timestamp
    page.meta["localized-time"] = self.util.get_localized_date(
  File "/opt/homebrew/lib/python3.10/site-packages/mkdocs_blogging_plugin/util.py", line 153, in get_localized_date
    return format_datetime(time, format="short", locale=_locale)
  File "/opt/homebrew/lib/python3.10/site-packages/babel/dates.py", line 719, in format_datetime
    locale = Locale.parse(locale)
  File "/opt/homebrew/lib/python3.10/site-packages/babel/core.py", line 317, in parse
    raise TypeError(f"Unexpected value for identifier: {identifier!r}")
TypeError: Unexpected value for identifier: None

@liang2kl
Copy link
Owner

liang2kl commented Jul 21, 2023

This may be fixed with a fallback to a default language code.

                if sys.version_info[:2] < (3, 11):
                    _locale = locale.getdefaultlocale()[0]
                else:
                    _locale = locale.getlocale()[0]
                # Fallback to en_US if locale environment is not set
                if not _locale:
                    _locale = "en_US"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants