Browse Source

Avoid UnicodeEncodeError when redirecting standalone output

NK 7 years ago
parent
commit
cda9f8593f
1 changed files with 4 additions and 1 deletions
  1. 4
    1
      utils/standalone_searx.py

+ 4
- 1
utils/standalone_searx.py View File

25
 # initialization
25
 # initialization
26
 from json import dumps
26
 from json import dumps
27
 from searx import settings
27
 from searx import settings
28
+import sys
29
+import codecs
28
 import searx.query
30
 import searx.query
29
 import searx.search
31
 import searx.search
30
 import searx.engines
32
 import searx.engines
97
     "paging": result_container.paging,
99
     "paging": result_container.paging,
98
     "results_number": result_container.results_number()
100
     "results_number": result_container.results_number()
99
 }
101
 }
102
+sys.stdout = codecs.getwriter("UTF-8")(sys.stdout)
103
+sys.stdout.write(dumps(result_container_json, sort_keys=True, indent=4, ensure_ascii=False, encoding="utf-8", default=json_serial))
100
 
104
 
101
-print(dumps(result_container_json, sort_keys=True, indent=4, ensure_ascii=False, encoding="utf-8", default=json_serial))