question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError: "Style 'normal' not found in stylesheet"

See original GitHub issue

v0.95 seem to have introduced a bug which results in KeyError: "Style 'normal' not found in stylesheet":

Steps to reproduce

  1. Create a directory:
cd /tmp
mkdir repro
cd repro
  1. Create Vagrantfile with following contents:
# -*- mode: ruby -*-
# vi: set ft=ruby :

$script = <<-SCRIPT
sudo apt-get update
sudo apt-get install python python-pip python-virtualenv -y
python -V
virtualenv .venv
source .venv/bin/activate
pip install rst2pdf==0.95
touch empty.rst
rst2pdf ./empty.rst -o result.pdf
SCRIPT


Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.provision "shell", inline: $script
end
  1. Run vagrant up

In the end script fails with:

    default: Traceback (most recent call last):
    default:   File "/home/vagrant/.venv/bin/rst2pdf", line 8, in <module>
    default:
    default: sys.exit(main())
    default:   File "/home/vagrant/.venv/local/lib/python2.7/site-packages/rst2pdf/createpdf.py", line 1491, in main
    default:
    default: strip_elements_with_classes=options.strip_elements_with_classes,
    default:   File "/home/vagrant/.venv/local/lib/python2.7/site-packages/rst2pdf/createpdf.py", line 173, in __init__
    default:
    default: self.loadStyles(stylesheets)
    default:   File "/home/vagrant/.venv/local/lib/python2.7/site-packages/rst2pdf/createpdf.py", line 276, in loadStyles
    default:
    default: def_dpi=self.def_dpi)
    default:   File "/home/vagrant/.venv/local/lib/python2.7/site-packages/rst2pdf/styles.py", line 532, in __init__
    default:
    default: self.emsize = self['base'].fontSize
    default:   File "/home/vagrant/.venv/local/lib/python2.7/site-packages/rst2pdf/styles.py", line 557, in __getitem__
    default:
    default: newst = copy(self.StyleSheet['normal'])
    default:   File "/home/vagrant/.venv/local/lib/python2.7/site-packages/reportlab/lib/styles.py", line 224, in __getitem__
    default:
    default: raise KeyError("Style '%s' not found in stylesheet" % key)
    default: KeyError
    default: :
    default: "Style 'normal' not found in stylesheet"
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

The issue is not present with v0.94.1

🖥 Versions

  • Python 2.7.17
  • rst2pdf==0.95
  • reportlab==3.5.32
  • Ubuntu 18.04
(.venv) vagrant@ubuntu-bionic:~$ pip freeze
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
docutils==0.15.2
Jinja2==2.10.3
MarkupSafe==1.1.1
pdfrw==0.4
Pillow==6.2.2
pkg-resources==0.0.0
Pygments==2.5.2
reportlab==3.5.32
rst2pdf==0.95
six==1.13.0
smartypants==2.0.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
roman-verchikovcommented, Jan 8, 2020

I can’t replicate this either, so I think it’s more complicated than being just one version or another. Does the styles/ directory mentioned in the first errors actually exist and does it contain files?

There is no styles directory in rst2pdf:

(.venv) vagrant@ubuntu-bionic:~$ ls .venv/lib/python2.7/site-packages/rst2pdf/styles
ls: cannot access '.venv/lib/python2.7/site-packages/rst2pdf/styles': No such file or directory

But there is styles.py file. It may conflict with the styles directory, if styles directory contains __init__.py. I suspect there might be a bug in setup.py or setup.cfg.

1reaction
akrabatcommented, May 9, 2020

0.97 is now release with this fix in it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

KeyError when trying to access ['style'] using Beautiful Soup
KeyError when trying to access ['style'] using Beautiful Soup · No, the div tag has no style attribute. I don't see any tag...
Read more >
KeyError: "Style 'normal' not found in stylesheet" - Bountysource
KeyError : "Style 'normal' not found in stylesheet"
Read more >
src/reportlab/lib/styles.py - Fossies
10 11 ParagraphStyle shows all the attributes available for formatting ... KeyError: 224 raise KeyError("Style '%s' not found in stylesheet" ...
Read more >
Working with Styles — python-docx 0.8.11 documentation
Working with Styles¶ ... styles['Normal'] <docx.styles.style. ... User-defined styles, also known as custom styles, are not localized and are accessed with ...
Read more >
Python KeyError Exceptions and How to Handle Them
When you see a KeyError , the semantic meaning is that the key being looked for could not be found. In the example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found