drm / jinja2-lint

Simple python script to lint jinja2 templates.
Other
61 stars 25 forks source link

AttributeError: 'str' object has no attribute 'decode' #8

Closed jhcook closed 5 years ago

jhcook commented 6 years ago

Good job! But, I ran into this.

https://stackoverflow.com/questions/28583565/str-object-has-no-attribute-decode-python-3-error

[vagrant@rhel7-vbox ansible]$ ./j2lint.py roles/openshift-openbanking/templates/master-config.j2
Traceback (most recent call last):
  File "./j2lint.py", line 44, in <module>
    main()
  File "./j2lint.py", line 39, in main
    check(fn, sys.stdout, sys.stderr, **kwargs), sys.argv[1:], 0))
  File "./j2lint.py", line 39, in <lambda>
    check(fn, sys.stdout, sys.stderr, **kwargs), sys.argv[1:], 0))
  File "./j2lint.py", line 24, in check
    env.get_template(template)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/Jinja2-2.10-py3.6.egg/jinja2/environment.py", line 830, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/Jinja2-2.10-py3.6.egg/jinja2/environment.py", line 804, in _load_template
    template = self.loader.load(self, name, globals)
  File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/Jinja2-2.10-py3.6.egg/jinja2/loaders.py", line 113, in load
    source, filename, uptodate = self.get_source(environment, name)
  File "./j2lint.py", line 18, in get_source
    source = file.read().decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
[vagrant@rhel7-vbox ansible]$ vi j2lint.py
[vagrant@rhel7-vbox ansible]$ ./j2lint.py roles/openshift-openbanking/templates/master-config.j2
roles/openshift-openbanking/templates/master-config.j2: Syntax check failed: unexpected '}' in roles/openshift-openbanking/templates/master-config.j2 at 72
[vagrant@rhel7-vbox ansible]$ vi roles/openshift-openbanking/templates/master-config.j2
[vagrant@rhel7-vbox ansible]$ ./j2lint.py roles/openshift-openbanking/templates/master-config.j2
roles/openshift-openbanking/templates/master-config.j2: Syntax OK
drm commented 5 years ago

seems you're not the only one. It was fixed as part of #7

jhcook commented 5 years ago

Thank you. Much appreciated.