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

encoding error in werkzeug-0.9.6 on Python 3.3.5 #551

Closed
gaoweiqiao opened this issue Jul 15, 2014 · 11 comments
Closed

encoding error in werkzeug-0.9.6 on Python 3.3.5 #551

gaoweiqiao opened this issue Jul 15, 2014 · 11 comments

Comments

@gaoweiqiao
Copy link

when i use flask0.10.1 to write view_function and template ,it throw UnicodeDecodeError.
i find the Error is thrown at “source = f.read()” in tbtools.py.
when i edit the source code "f = open(self.filename)" to "f = open(self.filename,encoding='utf-8')". the error is fixed.
so i think there maybe is a issue at "f = open(self.filename)"(line number is 463) on python 3.3.5

Error is "UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 353: illegal multibyte sequence".and "File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\debug\tbtools.py", line 467, in sourcelines
source = f.read()"

@untitaker
Copy link
Contributor

Can you post the full traceback, indented by four spaces (so the formatting doesn't break)?

@gaoweiqiao
Copy link
Author

Error on request:
Traceback (most recent call last):
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\serving.py", line 177, in run_wsgi
    execute(self.server.app)
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\serving.py", line 167, in execute
    for data in application_iter:
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\debug__init__.py", line 121, in debug_application
    secret=self.secret)
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\debug\tbtools.py", line 339, in render_full
     'summary': self.render_summary(include_title=False),
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\debug\tbtools.py", line 315, in render_summary
     frame.render()
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\debug\tbtools.py", line 402, in render
     'current_line': escape(self.current_line.strip())
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\debug\tbtools.py", line 500, in current_line
     return self.sourcelines[self.lineno - 1]
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\utils.py", line 71, in get
     value = self.func(obj)
File "C:\Python33\lib\site-packages\werkzeug-0.9.6-py3.3.egg\werkzeug\debug\tbtools.py", line 467, in sourcelines
     source = f.read()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 779: illegal multibyte sequence
unicodeerror

@mitsuhiko
Copy link
Contributor

Can you verify it the same problem appears in Python 2.7?

@gaoweiqiao
Copy link
Author

This is too weird!
I run the code (which has unicode error on python 3.3) on python 2.7. It does not have any error.
then i run the code on python 3.3 again, it still does not have any error.
i don‘t know why

@gaoweiqiao
Copy link
Author

When I rediscovered the error, I will try the code on python2.7

@gaoweiqiao
Copy link
Author

i get it.
it is not the problem caused by encoding。
i write some wrong code(for example,url_for("view"),i forget add blueprint name before view). when the wrong code run in python 2.7. python2.7 tell me why i am wrong, but python 3.3 tell me unicodeDecodeError.
so when i fix the code in python2.7 ,python 3.3 also has no problem.

after i change the source code "f = open(self.filename)" to "f = open(self.filename,encoding='utf-8')" in python 3.3,when i write some wrong code ,i get the error info the same with python 2.7.

thank you for the attention

@untitaker
Copy link
Contributor

Is the sourcecode change in your own application or in Werkzeug?

@gaoweiqiao
Copy link
Author

I don't change the source code of werkzeug or flask.

@untitaker
Copy link
Contributor

Okay, i thought because the line f = open(self.filename) is also present in Werkzeug, exactly in tbtools.py where the error was happening. Still not sure whether this error is purely in your application.

@gaoweiqiao
Copy link
Author

maybe.
thank you for your answer.

@Ppjet6
Copy link

Ppjet6 commented Jul 16, 2014

I just got about the same traceback and tbtools.py is actually missing this encoding='utf-8' argument for python3 to work correctly.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants