narusemotoki / replacer

This is plugin of Pelican. You can replace a text of a generated HTML.
GNU Affero General Public License v3.0
1 stars 0 forks source link

[Bug] CRITICAL: AttributeError: 'str' object has no attribute 'decode' #1

Closed Kristinita closed 7 years ago

Kristinita commented 7 years ago

1. Summary

If I use replacer, I get critical error.

2. Settings

Part of my Makefile:

html:
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)

Part of my pelicanconf.py:

PLUGIN_PATHS = ['pelican-plugins']
PLUGINS = ['replacer']

REPLACES = (
    (u'css\\/personal', u'..\\/css\\/personal'),
)

3. Steps to reproduce

In root folder of my project I run command make html.

4. Expected behavior

Successful replace css/personal../css/personal. About reasons see here.

5. Actual behavior

d:\Kristinita>make html
pelican d:/Kristinita/content -o d:/Kristinita/output -s d:/Kristinita/pelicanconf.py
CRITICAL: AttributeError: 'str' object has no attribute 'decode'
make: *** [makefile:65: html] Error 1

If I disable replacer in my pelicanconf.py, I don't get actual behavior, I successful build my site.

6. Environment

Operating system and version: Windows 10 Enterprise LTSB 64-bit EN Python: 3.6.1 Pelican: 3.7.1 Make for Windows: 4.2

Thanks.

narusemotoki commented 7 years ago

Hello @Kristinita Thank you for your great bug report. But unfortunately I couldn't reproduce it. Could you add --debug to html part of your Makefile?

html:
    $(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) --debug

Then next time you run make html, you will get more detail of the CRITICAL error. Could you give me that? i.e. (This is the face. I made changes for the example.)

CRITICAL: AttributeError: 'str' object has no attribute 'decode'
Traceback (most recent call last):
  File "/usr/local/bin/pelican", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.5/dist-packages/pelican/__init__.py", line 478, in main
    pelican.run()
  File "/usr/local/lib/python3.5/dist-packages/pelican/__init__.py", line 183, in run
    p.generate_output(writer)
  File "/usr/local/lib/python3.5/dist-packages/pelican/generators.py", line 587, in generate_output
    self.generate_pages(writer)
  File "/usr/local/lib/python3.5/dist-packages/pelican/generators.py", line 488, in generate_pages
    self.generate_direct_templates(write)
  File "/usr/local/lib/python3.5/dist-packages/pelican/generators.py", line 436, in generate_direct_templates
    page_name=os.path.splitext(save_as)[0])
  File "/usr/local/lib/python3.5/dist-packages/pelican/writers.py", line 206, in write_file
    page.save_as, override_output)
  File "/usr/local/lib/python3.5/dist-packages/pelican/writers.py", line 168, in _write_file
    signals.content_written.send(path, context=localcontext)
  File "/usr/lib/python3/dist-packages/blinker/base.py", line 267, in send
    for receiver in self.receivers_for(sender)]
  File "/usr/lib/python3/dist-packages/blinker/base.py", line 267, in <listcomp>
    for receiver in self.receivers_for(sender)]
  File "plugins/replacer/replacer.py", line 19, in replace
    s = s.replace(src.decode(), tgt)
AttributeError: 'str' object has no attribute 'decode'
Makefile:65: recipe for target 'html' failed
make: *** [html] Error 1
Kristinita commented 7 years ago

@narusemotoki, yes, I'm sorry. Also I use Cyrillic symbols in filenames and in content of my pages.

Click here to see full output.
```python D:\Kristinita>pelican content --debug DEBUG: Pelican version: 3.7.1 DEBUG: Python version: 3.6.1 DEBUG: Adding current directory to system path DEBUG: Temporarily adding PLUGIN_PATHS to system path DEBUG: Loading plugin `pagefixer` DEBUG: Registering plugin `pagefixer` DEBUG: Loading plugin `pelican_javascript` DEBUG: Registering plugin `pelican_javascript` DEBUG: Loading plugin `sitemap` DEBUG: Registering plugin `sitemap` DEBUG: Loading plugin `section_number` DEBUG: Registering plugin `section_number` DEBUG: Loading plugin `replacer` DEBUG: Registering plugin `replacer` DEBUG: Restoring system path DEBUG: Found generator: DEBUG: Template list: ['!simple/archives.html', '!simple/article.html', '!simple/author.html', '!simple/authors.html', '!simple/base.html', '!simple/categories.html', '!simple/category.html', '!simple/gosquared.html', '!simple/index.html', '!simple/page.html', '!simple/pagination.html', '!simple/period_archives.html', '!simple/tag.html', '!simple/tags.html', '!simple/translations.html', '404.html', 'about.html', 'archives.html', 'article.html', 'author.html', 'authors.html', 'base.html', 'categories.html', 'category.html', 'gosquared.html', 'index.html', 'page.html', 'pagination.html', 'period_archives.html', 'sasha-black.html', 'tag.html', 'tags.html', 'translations.html'] DEBUG: Skipping deletion; .git is on retention list: D:\Kristinita\output\.git DEBUG: Deleted directory D:\Kristinita\output\css DEBUG: Deleted directory D:\Kristinita\output\feeds DEBUG: Deleted file/link D:\Kristinita\output\index.html DEBUG: Deleted directory D:\Kristinita\output\js DEBUG: Read file Gingerinas/Korvers.md -> Page DEBUG: Signal page_generator_preread.send(PagesGenerator) DEBUG: Successfuly imported extension module "markdown.extensions.codehilite". DEBUG: Successfully loaded extension "markdown.extensions.codehilite.CodeHiliteExtension". DEBUG: Successfuly imported extension module "markdown.extensions.extra". DEBUG: Successfuly imported extension module "markdown.extensions.smart_strong". DEBUG: Successfully loaded extension "markdown.extensions.smart_strong.SmartEmphasisExtension". DEBUG: Successfuly imported extension module "markdown.extensions.fenced_code". DEBUG: Successfully loaded extension "markdown.extensions.fenced_code.FencedCodeExtension". DEBUG: Successfuly imported extension module "markdown.extensions.footnotes". DEBUG: Successfully loaded extension "markdown.extensions.footnotes.FootnoteExtension". DEBUG: Successfuly imported extension module "markdown.extensions.attr_list". DEBUG: Successfully loaded extension "markdown.extensions.attr_list.AttrListExtension". DEBUG: Successfuly imported extension module "markdown.extensions.def_list". DEBUG: Successfully loaded extension "markdown.extensions.def_list.DefListExtension". DEBUG: Successfuly imported extension module "markdown.extensions.tables". DEBUG: Successfully loaded extension "markdown.extensions.tables.TableExtension". DEBUG: Successfuly imported extension module "markdown.extensions.abbr". DEBUG: Successfully loaded extension "markdown.extensions.abbr.AbbrExtension". DEBUG: Successfully loaded extension "markdown.extensions.extra.ExtraExtension". DEBUG: Successfuly imported extension module "markdown.extensions.meta". DEBUG: Successfully loaded extension "markdown.extensions.meta.MetaExtension". DEBUG: Signal page_generator_context.send(PagesGenerator, ) DEBUG: Read file Gingerinas/Книги-для-джинджерин.md -> Page DEBUG: Read file Giologica/Nas-Izu.md -> Page DEBUG: Read file Giologica/Valerywork-Kiravel.md -> Page DEBUG: Read file Giologica/Демагогия-Нестеренко.md -> Page DEBUG: Read file Giologica/Комментарии-к-материалам-о-неконструктивных-методах-ведения-дискуссии.md -> Page DEBUG: Read file Life-hacks/Default-portable-browser-Windows-10.md -> Page WARNING: Empty alt attribute for image gQywm8B.png in D:\Kristinita\content\Life-hacks\Default-portable-browser-Windows-10.md WARNING: Empty alt attribute for image HCIt8xR.png in D:\Kristinita\content\Life-hacks\Default-portable-browser-Windows-10.md WARNING: Empty alt attribute for image l9HgjBJ.png in D:\Kristinita\content\Life-hacks\Default-portable-browser-Windows-10.md WARNING: Empty alt attribute for image LNFEjsi.png in D:\Kristinita\content\Life-hacks\Default-portable-browser-Windows-10.md WARNING: Other images have empty alt attributes DEBUG: Read file Life-hacks/Как-автоматически-входить-на-сайты.md -> Page DEBUG: Read file Sasha-Black/Sasha-Black-description.md -> Page DEBUG: Read file Smert-svobode/Новые-недовольные-русские.md -> Page DEBUG: Read file Sublime-Text/SashaSublime.md -> Page DEBUG: Read file Sublime-Text/Sublime-Text-Power-User-notes.md -> Page DEBUG: Read file Sublime-Text/ValeriyaSpeller.md -> Page DEBUG: Read file .bowerrc -> Static DEBUG: Signal static_generator_preread.send(StaticGenerator) DEBUG: Signal static_generator_context.send(StaticGenerator, ) DEBUG: Read file .editorconfig -> Static DEBUG: Read file .gitattributes -> Static DEBUG: Read file 404.md -> Static DEBUG: Read file android-chrome-192x192.png -> Static DEBUG: Read file android-chrome-512x512.png -> Static DEBUG: Read file apple-touch-icon.png -> Static DEBUG: Read file browserconfig.xml -> Static DEBUG: Read file favicon-16x16.png -> Static DEBUG: Read file favicon-32x32.png -> Static DEBUG: Read file favicon16×16.ico -> Static DEBUG: Read file manifest.json -> Static DEBUG: Read file mozoleglazym.html -> Static DEBUG: Read file mstile-150x150.png -> Static DEBUG: Read file opensearch.xml -> Static DEBUG: Read file package.json -> Static DEBUG: Read file README.MD -> Static DEBUG: Read file safari-pinned-tab.svg -> Static DEBUG: Read file Sasha-Black.html -> Static DEBUG: Read file css/personal/Life-hacks/default-portable-browser.css -> Static DEBUG: Read file css/personal/Sasha-Black/sasha-black-description.css -> Static DEBUG: Read file extra/CNAME -> Static DEBUG: Read file extra/robots.txt -> Static DEBUG: Read file extra/verifyforzoho.HTML -> Static DEBUG: Read file favicons/favicon.ico -> Static DEBUG: Read file Gingerinas/Тренажёр-реакции.HTML -> Static DEBUG: Read file Gingerinas/Часы-для-концентрации.swf -> Static DEBUG: Read file images/banners/Баннер_1.swf -> Static DEBUG: Read file images/banners/Сашин_баннер.gif -> Static DEBUG: Read file images/donate_files/Bitcoin-Donate-button.png -> Static DEBUG: Read file images/donate_files/Bitcoin-HTML-Redirect.HTML -> Static DEBUG: Read file images/donate_files/Bitcoin-Redirect.HTML -> Static DEBUG: Read file images/donate_files/Litecoin-Donate-button.png -> Static DEBUG: Read file images/donate_files/Litecoin-HTML-Redirect.HTML -> Static DEBUG: Read file images/donate_files/Litecoin-Redirect.HTML -> Static DEBUG: Read file images/donate_files/PayPal-Donate-Button-Dollar.png -> Static DEBUG: Read file images/donate_files/PayPal-Donate-Button-Euro.png -> Static DEBUG: Read file images/gingerinas/4_14_7.png -> Static DEBUG: Read file images/giologica/Kiravel.jpg -> Static DEBUG: Read file images/giologica/Strelena.png -> Static DEBUG: Read file images/giologica/Valerywork.jpg -> Static DEBUG: Read file images/giologica/Конформизм_в_рекламе.png -> Static DEBUG: Read file images/giologica/Настя_Изюмина.jpg -> Static DEBUG: Read file images/giologica/Пирамида_Грэма.jpg -> Static DEBUG: Read file images/interface_images/clippy.svg -> Static DEBUG: Read file images/logo/Sasha_Black_logo.jpg -> Static DEBUG: Read file images/logo/Логотип_без_красного.jpeg -> Static DEBUG: Read file images/logo/Логотип_с_жирным_шрифтом.jpg -> Static DEBUG: Read file images/logo/Логотип_с_тонким_шрифтом.jpeg -> Static DEBUG: Read file images/reaction_trainer_images/jswb1.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest_continue.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest_done.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest_go.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest_ready.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest_stoplight_green.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest_stoplight_red.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest_stoplight_yellow.gif -> Static DEBUG: Read file images/reaction_trainer_images/rttest_wait.gif -> Static DEBUG: Read file images/reaction_trainer_images/transparent.gif -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/2IP.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Avast!.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/DNSBL.info.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Dr.Web.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Gimpel.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Is_It_Hacked.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/MX_Toolbox.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Quttera.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Robtex1.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Robtex2.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Robtex3.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Robtex4.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Rosinstrument.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Sucuri.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/TAG.Hosting.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/TrustPilot.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/TrustScam.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/urlQuery.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/URL_Void.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/VirusTotal.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/vURL.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Webutation.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Web_of_Trust.jpg -> Static DEBUG: Read file images/sasha-black/Kristinita's_examples/Xseo.jpg -> Static DEBUG: Read file images/sasha-black/other_images/MX_Toolbox_проверяет_usenet.nl.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Question_Mark.png -> Static DEBUG: Read file images/sasha-black/other_images/Quttera_сканирует_флоранимал.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Sucuri_сканирует_usenet.nl.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Sucuri_сканирует_флоранимал.jpg -> Static DEBUG: Read file images/sasha-black/other_images/URL_Void_проверяет_флоранимал1.jpg -> Static DEBUG: Read file images/sasha-black/other_images/URL_Void_проверяет_флоранимал2.jpg -> Static DEBUG: Read file images/sasha-black/other_images/WOT_badges.jpg -> Static DEBUG: Read file images/sasha-black/other_images/WOT_плашка.jpg -> Static DEBUG: Read file images/sasha-black/other_images/WOT_проверяет_usenet.nl.jpg -> Static DEBUG: Read file images/sasha-black/other_images/WOT_проверяет_флоранимал.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Аддон_Webutation.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Комментарии_WOT.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Ответ_владельца_в_Trustpilot.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Оценивание_Trustpilot.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Оценка_Кристините_на_WOT.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Предупреждение_Dr.Web'а.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Предупреждение_Аваста.jpg -> Static DEBUG: Read file images/sasha-black/other_images/Предупреждение_Яндекса.jpg -> Static DEBUG: Read file js/Details-Polyfill/details.polyfill.js -> Static DEBUG: Read file js/Details-Polyfill/details1.js -> Static DEBUG: Read file js/Details-Polyfill/details2.js -> Static DEBUG: Read file js/personal/Kristinita/accesskeys.js -> Static DEBUG: Read file js/personal/Kristinita/bowser.js -> Static DEBUG: Read file js/personal/Kristinita/gcse.js -> Static DEBUG: Read file js/personal/Kristinita/siteheart.js -> Static DEBUG: Read file js/personal/Mail/personal-mail.js -> Static DEBUG: Read file js/personal/Sasha Black/Sasha-Black.js -> Static DEBUG: Read file Kristinita's-Search/actual_catalogue.txt -> Static DEBUG: Read file Kristinita's-Search/catalogue.HTML -> Static DEBUG: Read file Kristinita's-Search/checkout.HTML -> Static DEBUG: Read file Kristinita's-Search/description.HTML -> Static DEBUG: Read file Kristinita's-Search/examples.HTML -> Static DEBUG: Read file Kristinita's-Search/Проверенные_каталоги.txt -> Static DEBUG: Read file PelicanHeader/TestModified.md -> Static -> Writing D:\Kristinita\output\feeds/all.atom.xml -> Writing D:\Kristinita\output\index.html CRITICAL: AttributeError: 'str' object has no attribute 'decode' Traceback (most recent call last): File "c:\python36\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\python36\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Python36\Scripts\pelican.EXE\__main__.py", line 9, in File "c:\python36\lib\site-packages\pelican\__init__.py", line 487, in main pelican.run() File "c:\python36\lib\site-packages\pelican\__init__.py", line 179, in run p.generate_output(writer) File "c:\python36\lib\site-packages\pelican\generators.py", line 600, in generate_output self.generate_pages(writer) File "c:\python36\lib\site-packages\pelican\generators.py", line 496, in generate_pages self.generate_direct_templates(write) File "c:\python36\lib\site-packages\pelican\generators.py", line 444, in generate_direct_templates page_name=os.path.splitext(save_as)[0]) File "c:\python36\lib\site-packages\pelican\writers.py", line 224, in write_file page.save_as, override_output) File "c:\python36\lib\site-packages\pelican\writers.py", line 184, in _write_file signals.content_written.send(path, context=localcontext) File "c:\python36\lib\site-packages\blinker\base.py", line 267, in send for receiver in self.receivers_for(sender)] File "c:\python36\lib\site-packages\blinker\base.py", line 267, in for receiver in self.receivers_for(sender)] File "D:\Kristinita\pelican-plugins\replacer\replacer.py", line 15, in replace s = s.decode('utf-8').replace(src.decode('utf-8'), tgt.decode('utf-8')) AttributeError: 'str' object has no attribute 'decode' D:\Kristinita> ```

Thanks.
narusemotoki commented 7 years ago

@Kristinita I fixed the bug. I'm sorry, now I understand why I couldn't reproduce the bug last time. It is because I didn't push the latest plugin on GitHub. Now I remember I got same error when I moved to Python3 for Pelican.

narusemotoki commented 7 years ago

@Kristinita I closed this issue, but if you still get the error, let me know.