JetBrains / teamcity-messages

Python Unit Test Reporting to TeamCity
https://pypi.python.org/pypi/teamcity-messages
Apache License 2.0
138 stars 81 forks source link

UnicodeEncodeError on flake8 #122

Open cyberMe opened 7 years ago

cyberMe commented 7 years ago

UnicodeEncodeError raised when Flake8 check files with unicode text.

Environment: python 2.7.13, flake8==3.2.1, teamcity-messages==1.21.

Sample file:

# coding: utf-8

SomeVa='fsdf ываыва'  # Non ascci symbols

Command for run sample: flake8 --teamcity=True --output=report.txt

Stacktrace:

Traceback (most recent call last):
  File ".../bin/flake8", line 11, in <module>
    sys.exit(main())
  File ".../lib/python2.7/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File ".../lib/python2.7/site-packages/flake8/main/application.py", line 322, in run
    self._run(argv)
  File ".../lib/python2.7/site-packages/flake8/main/application.py", line 308, in _run
    self.report_errors()
  File ".../lib/python2.7/site-packages/flake8/main/application.py", line 274, in report_errors
    results = self.file_checker_manager.report()
  File ".../lib/python2.7/site-packages/flake8/checker.py", line 305, in report
    results)
  File ".../lib/python2.7/site-packages/flake8/checker.py", line 215, in _handle_results
    physical_line=physical_line,
  File ".../lib/python2.7/site-packages/flake8/style_guide.py", line 284, in handle_error
    self.formatter.handle(error)
  File ".../lib/python2.7/site-packages/flake8/formatting/base.py", line 69, in handle
    self.write(line, source)
  File ".../lib/python2.7/site-packages/flake8/formatting/base.py", line 170, in write
    self._write(line)
  File ".../lib/python2.7/site-packages/flake8/formatting/base.py", line 152, in _write
    self.output_fd.write(output + self.newline)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 222-227: ordinal not in range(128)
shalupov commented 7 years ago

What's interesting: flake8 --teamcity --output=report.txt works fine

cyberMe commented 7 years ago

Yes, but argument --output=report.txt is not processed, and report.txt is not created.

Another way for reproduce that exception:

I think, the reason is that flake doesn't expect unicode characters in error message.

Also this error is reproduced at latest flake8==3.3.0.