Browse Source

Merge pull request #980 from nikaiw/master

Avoid UnicodeEncodeError when redirecting standalone output
Adam Tauber 7 years ago
parent
commit
081f51db4e
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))