Browse Source

Bugfix foo_pep333.py for uwsgi

uwsgi do not handle str, only bytes.
Yann Weber 4 years ago
parent
commit
1456e35e96
2 changed files with 7 additions and 4 deletions
  1. 4
    0
      README
  2. 3
    4
      foo_pep333.py

+ 4
- 0
README View File

@@ -28,3 +28,7 @@ Example : linking against a debug build of python :
28 28
 logging to file example :
29 29
 -------------------------
30 30
 -L '/tmp/foo.log;0xff;{datetime} {msg} {ident}'
31
+
32
+uwsgi equivalent :
33
+------------------
34
+uwsgi_python3 --fastcgi-socket 127.0.0.1:9000 --module foo_pep333:entrypoint --processes=5

+ 3
- 4
foo_pep333.py View File

@@ -5,7 +5,6 @@ from pprint import pformat
5 5
 
6 6
 def entrypoint(env, start_response):
7 7
 	write_body = start_response("200 OK", [('Content-type', 'text/plain')])
8
-
9 8
 	if not "wsgi.input" in env:
10 9
 		raise ValueError("Given environ does not contain any 'wsgi.input' key !")
11 10
 	data_in = env["wsgi.input"]
@@ -14,8 +13,8 @@ def entrypoint(env, start_response):
14 13
 	#data = data_in.readlines()
15 14
 	while True:
16 15
 		data = data_in.read(98)
17
-		write_body("POST data : %s\n====\n" % repr(data))
16
+		write_body(("POST data : %s\n====\n" % repr(data)).encode())
18 17
 		if not data:
19 18
 			break
20
-	write_body("Environ data :\n'%s'\n====\n" % pformat(env))
21
-	return ['Hello world !\n']
19
+	write_body(("Environ data :\n'%s'\n====\n" % pformat(env)).encode())
20
+	return [b'Hello world !\n']

Loading…
Cancel
Save