-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
test summary.py fails on python 3.8 with: AttributeError: module 'cgi' has no attribute 'escape' #20032
Copy link
Copy link
Closed
Milestone
Description
modules/ts/misc/summary.py fails in Python 3.8 due to cgi.escape was removed in Python 3.8.
Traceback (most recent call last):
File "../modules/ts/misc/summary.py", line 289, in <module>
htmlPrintHeader(sys.stdout, "Summary report for %s tests from %s test logs" % (len(test_cases), setsCount))
File "/mnt/c/repos-nobackup/opencv/modules/ts/misc/table_formatter.py", line 470, in htmlPrintHeader
titletag = "<title>%s</title>\n" % htmlEncode([str(title)])
File "/mnt/c/repos-nobackup/opencv/modules/ts/misc/table_formatter.py", line 26, in htmlEncode
return '<br/>'.join([cgi.escape(s) for s in str])
File "/mnt/c/repos-nobackup/opencv/modules/ts/misc/table_formatter.py", line 26, in <listcomp>
return '<br/>'.join([cgi.escape(s) for s in str])
AttributeError: module 'cgi' has no attribute 'escape'
As reported at https://bugzilla.redhat.com/show_bug.cgi?id=1827745
cgi.escape which was deprecated in Python 3.7 and removed in 3.8. A possible alternative is html.escape.
Setup
- Ubuntu 20.04.2 LTS
- Python 3.8.5 fails when run
- OpenCV 4.5.2
Repro
- Create multiple performance test output XML files with
run.py - Create summary report that combines that multiple output, e.g.
python3 modules/ts/misc/summary.py -o html *.xml > report.html
Result
Traceback (most recent call last):
File "../modules/ts/misc/summary.py", line 289, in <module>
htmlPrintHeader(sys.stdout, "Summary report for %s tests from %s test logs" % (len(test_cases), setsCount))
File "/mnt/c/repos-nobackup/opencv/modules/ts/misc/table_formatter.py", line 470, in htmlPrintHeader
titletag = "<title>%s</title>\n" % htmlEncode([str(title)])
File "/mnt/c/repos-nobackup/opencv/modules/ts/misc/table_formatter.py", line 26, in htmlEncode
return '<br/>'.join([cgi.escape(s) for s in str])
File "/mnt/c/repos-nobackup/opencv/modules/ts/misc/table_formatter.py", line 26, in <listcomp>
return '<br/>'.join([cgi.escape(s) for s in str])
AttributeError: module 'cgi' has no attribute 'escape'
Expected
No errors and a summary html output.
Workaround
This issue is widely reported on the internet https://www.google.com/search?q=AttributeError%3A+module+%27cgi%27+has+no+attribute+%27escape%27
Most everyone has the same approach, to replace cgi.escape with html.escape. Naturally, you will need to consider any compatibility issues with prior versions including if 2.x is desired to be supported.
Reactions are currently unavailable