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,6 +25,8 @@ path.append(realpath(dirname(realpath(__file__)) + '/../'))
25 25
 # initialization
26 26
 from json import dumps
27 27
 from searx import settings
28
+import sys
29
+import codecs
28 30
 import searx.query
29 31
 import searx.search
30 32
 import searx.engines
@@ -97,5 +99,6 @@ result_container_json = {
97 99
     "paging": result_container.paging,
98 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))