Hi, I'm trying to wrap a wsgi application into Pylons. The wsgi is the bazaar (bzr) server, a dvcs like mercurial or git. Anyway I first tried a simple wsgi application with gunicorn and it worked very well but so far my efforts to use Pylons were unsuccessfull.
>From what I understand, the bzr client sends POST request with an unencoded form, pretending to be x-www-form-encoded. This unencoded form is transmitted as is by gunicorn to the wsgi application via environ['wsgi.input']. This makes the bzr server happy. When using Pylons the environ['wsgi.input'] variable contains an encoded string that looks like urlencoded. However using urllib.unquote_plus does not manage to translate the string back to what was originally transmitted. Below is an example of the problem. There seems to be some alterations of the original POST body. Is there a way to correcly decode the strings or even not having Pylons (or any of its components) encode it first ? # I have this python string from environ['wsgi.input'] (in Pylons) ['bzr+message+3+%28bzr+1.6%29%0A%00%00%00%1Cd16%3ASoftware +version5%3A2.1.2es%00%00%00%27l29%3ARepository.insert_stream_1.191%3A. 0%3Aeb%00%00%00%2ABazaar+pack+format+1+%28introduced+in+0.18%29%0Ab %00%00%00=&B54%0A%0ABazaar+repository+format+2a+%28needs+bzr+1.16+or +later%29%0Ab%00%00%00%01Ee='] # while gunicorn's wsgi.input contains (directly, without decoding): """bzr message 3 (bzr 1.6) d16:Software version5:2.1.2es'l29:Repository.insert_stream_1.191:.0:eb*Bazaar pack format 1 (introduced in 0.18) b;B54 Bazaar repository format 2a (needs bzr 1.16 or later) bEe""" #To decode the Pylons' wsgi.input string, I tried with urllib.unquote_plus() which decodes to: """ bzr message 3 (bzr 1.6) d16:Software version5:2.1.2es'l29:Repository.insert_stream_1.191:.0:eb*Bazaar pack format 1 (introduced in 0.18) b=&B54 Bazaar repository format 2a (needs bzr 1.16 or later) bEe= """ # gunicorn plain wsgi.input and Pylons decoded are different. My wsgi application that takes wsgi.input looks happy with gunicorn version and returns an error with Pylons (undecoded or urllib.unquote_plus decoded) Here is a (filtered) tcp dump of the http stream: ========= With Pylons (errors) ================= First tcp packet: from bzr client to Paste server. HTTP header 0000 50 4f 53 54 20 2f 62 61 7a 61 61 72 2f 66 6f 6f POST /bazaar/ foo 0010 62 61 72 2f 2e 62 7a 72 2f 73 6d 61 72 74 20 48 bar/.bzr/smart H 0020 54 54 50 2f 31 2e 31 0d 0a 41 63 63 65 70 74 2d TTP/ 1.1..Accept- 0030 45 6e 63 6f 64 69 6e 67 3a 20 69 64 65 6e 74 69 Encoding: identi 0040 74 79 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 ty..Content- Leng 0050 74 68 3a 20 32 31 38 0d 0a 43 6f 6e 6e 65 63 74 th: 218..Connect 0060 69 6f 6e 3a 20 4b 65 65 70 2d 41 6c 69 76 65 0d ion: Keep- Alive. 0070 0a 41 63 63 65 70 74 3a 20 2a 2f 2a 0d 0a 55 73 .Accept: */ *..Us 0080 65 72 2d 41 67 65 6e 74 3a 20 62 7a 72 2f 32 2e er-Agent: bzr/ 2. 0090 31 2e 32 20 28 75 72 6c 6c 69 62 29 0d 0a 48 6f 1.2 (urllib)..Ho 00a0 73 74 3a 20 6c 6f 63 61 6c 68 6f 73 74 3a 35 30 st: localhost: 50 00b0 30 30 0d 0a 50 72 61 67 6d 61 3a 20 6e 6f 2d 63 00..Pragma: no- c 00c0 61 63 68 65 0d 0a 43 61 63 68 65 2d 43 6f 6e 74 ache..Cache- Cont 00d0 72 6f 6c 3a 20 6d 61 78 2d 61 67 65 3d 30 0d 0a rol: max- age=0.. 00e0 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 Content-Type: ap 00f0 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 77 77 77 2d plication/x- www- 0100 66 6f 72 6d 2d 75 72 6c 65 6e 63 6f 64 65 64 0d form- urlencoded. 0110 0a 0d 0a ... [server ack] Second packet: from bzr client to Paste server. HTTP message content 0000 62 7a 72 20 6d 65 73 73 61 67 65 20 33 20 28 62 bzr message 3 (b 0010 7a 72 20 31 2e 36 29 0a 00 00 00 1c 64 31 36 3a zr 1.6).....d16: 0020 53 6f 66 74 77 61 72 65 20 76 65 72 73 69 6f 6e Software version 0030 35 3a 32 2e 31 2e 32 65 73 00 00 00 27 6c 32 39 5:2.1.2es...'l29 0040 3a 52 65 70 6f 73 69 74 6f 72 79 2e 69 6e 73 65 :Repository.inse 0050 72 74 5f 73 74 72 65 61 6d 5f 31 2e 31 39 31 3a rt_stream_1.191: 0060 2e 30 3a 65 62 00 00 00 2a 42 61 7a 61 61 72 20 . 0:eb...*Bazaar 0070 70 61 63 6b 20 66 6f 72 6d 61 74 20 31 20 28 69 pack format 1 (i 0080 6e 74 72 6f 64 75 63 65 64 20 69 6e 20 30 2e 31 ntroduced in 0.1 0090 38 29 0a 62 00 00 00 3b 42 35 34 0a 0a 42 61 7a 8).b...;B54..Baz 00a0 61 61 72 20 72 65 70 6f 73 69 74 6f 72 79 20 66 aar repository f 00b0 6f 72 6d 61 74 20 32 61 20 28 6e 65 65 64 73 20 ormat 2a (needs 00c0 62 7a 72 20 31 2e 31 36 20 6f 72 20 6c 61 74 65 bzr 1.16 or late 00d0 72 29 0a 62 00 00 00 01 45 65 r).b....Ee * response from Pylons server: 0000 48 54 54 50 2f 31 2e 30 20 32 30 30 20 4f 4b 0d HTTP/1.0 200 OK. 0010 0a . 0000 53 65 72 76 65 72 3a 20 50 61 73 74 65 57 53 47 Server: PasteWSG 0010 49 53 65 72 76 65 72 2f 30 2e 35 20 50 79 74 68 IServer/0.5 Pyth 0020 6f 6e 2f 32 2e 36 2e 35 2b 0d 0a 44 61 74 65 3a on/ 2.6.5+..Date: 0030 20 57 65 64 2c 20 32 30 20 4f 63 74 20 32 30 31 Wed, 20 Oct 201 0040 30 20 31 35 3a 33 34 3a 32 33 20 47 4d 54 0d 0a 0 15:34:23 GMT.. 0050 43 6f 6e 74 65 6e 74 2d 74 79 70 65 3a 20 61 70 Content-type: ap 0060 70 6c 69 63 61 74 69 6f 6e 2f 6f 63 74 65 74 2d plication/ octet- 0070 73 74 72 65 61 6d 0d 0a 43 6f 6e 74 65 6e 74 2d stream..Content- 0080 4c 65 6e 67 74 68 3a 20 31 33 39 0d 0a 0d 0a 62 Length: 139....b 0090 7a 72 20 6d 65 73 73 61 67 65 20 33 20 28 62 7a zr message 3 (bz 00a0 72 20 31 2e 36 29 0a 00 00 00 1c 64 31 36 3a 53 r 1.6).....d16:S 00b0 6f 66 74 77 61 72 65 20 76 65 72 73 69 6f 6e 35 oftware version5 00c0 3a 32 2e 32 2e 31 65 6f 45 73 00 00 00 4b 6c 35 : 2.2.1eoEs...Kl5 00d0 3a 65 72 72 6f 72 36 33 3a 47 65 6e 65 72 69 63 :error63:Generic 00e0 20 62 7a 72 20 73 6d 61 72 74 20 70 72 6f 74 6f bzr smart proto 00f0 63 6f 6c 20 65 72 72 6f 72 3a 20 42 61 64 20 6d col error: Bad m 0100 65 73 73 61 67 65 20 6b 69 6e 64 20 62 79 74 65 essage kind byte 0110 3a 20 27 5c 78 30 30 27 65 65 : '\x00'ee (bzr protocol error. Bad message kind byte \x00) =============== With gunicorn (no Pylons, no error) ============ bzr client to gunicorn: 0000 50 4f 53 54 20 2f 62 61 7a 61 61 72 2f 66 6f 6f POST /bazaar/ foo 0010 62 61 72 2f 2e 62 7a 72 2f 73 6d 61 72 74 20 48 bar/.bzr/smart H 0020 54 54 50 2f 31 2e 31 0d 0a 41 63 63 65 70 74 2d TTP/ 1.1..Accept- 0030 45 6e 63 6f 64 69 6e 67 3a 20 69 64 65 6e 74 69 Encoding: identi 0040 74 79 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 ty..Content- Leng 0050 74 68 3a 20 32 31 38 0d 0a 43 6f 6e 6e 65 63 74 th: 218..Connect 0060 69 6f 6e 3a 20 4b 65 65 70 2d 41 6c 69 76 65 0d ion: Keep- Alive. 0070 0a 41 63 63 65 70 74 3a 20 2a 2f 2a 0d 0a 55 73 .Accept: */ *..Us 0080 65 72 2d 41 67 65 6e 74 3a 20 62 7a 72 2f 32 2e er-Agent: bzr/ 2. 0090 31 2e 32 20 28 75 72 6c 6c 69 62 29 0d 0a 48 6f 1.2 (urllib)..Ho 00a0 73 74 3a 20 6c 6f 63 61 6c 68 6f 73 74 3a 39 30 st: localhost: 90 00b0 30 30 0d 0a 50 72 61 67 6d 61 3a 20 6e 6f 2d 63 00..Pragma: no- c 00c0 61 63 68 65 0d 0a 43 61 63 68 65 2d 43 6f 6e 74 ache..Cache- Cont 00d0 72 6f 6c 3a 20 6d 61 78 2d 61 67 65 3d 30 0d 0a rol: max- age=0.. 00e0 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 Content-Type: ap 00f0 70 6c 69 63 61 74 69 6f 6e 2f 78 2d 77 77 77 2d plication/x- www- 0100 66 6f 72 6d 2d 75 72 6c 65 6e 63 6f 64 65 64 0d form- urlencoded. 0110 0a 0d 0a ... bzr client to gunicorn: same message as before 0000 62 7a 72 20 6d 65 73 73 61 67 65 20 33 20 28 62 bzr message 3 (b 0010 7a 72 20 31 2e 36 29 0a 00 00 00 1c 64 31 36 3a zr 1.6).....d16: 0020 53 6f 66 74 77 61 72 65 20 76 65 72 73 69 6f 6e Software version 0030 35 3a 32 2e 31 2e 32 65 73 00 00 00 27 6c 32 39 5:2.1.2es...'l29 0040 3a 52 65 70 6f 73 69 74 6f 72 79 2e 69 6e 73 65 :Repository.inse 0050 72 74 5f 73 74 72 65 61 6d 5f 31 2e 31 39 31 3a rt_stream_1.191: 0060 2e 30 3a 65 62 00 00 00 2a 42 61 7a 61 61 72 20 . 0:eb...*Bazaar 0070 70 61 63 6b 20 66 6f 72 6d 61 74 20 31 20 28 69 pack format 1 (i 0080 6e 74 72 6f 64 75 63 65 64 20 69 6e 20 30 2e 31 ntroduced in 0.1 0090 38 29 0a 62 00 00 00 3b 42 35 34 0a 0a 42 61 7a 8).b...;B54..Baz 00a0 61 61 72 20 72 65 70 6f 73 69 74 6f 72 79 20 66 aar repository f 00b0 6f 72 6d 61 74 20 32 61 20 28 6e 65 65 64 73 20 ormat 2a (needs 00c0 62 7a 72 20 31 2e 31 36 20 6f 72 20 6c 61 74 65 bzr 1.16 or late 00d0 72 29 0a 62 00 00 00 01 45 65 r).b....Ee Server response 0000 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK. 0010 0a 53 65 72 76 65 72 3a 20 67 75 6e 69 63 6f 72 .Server: gunicor 0020 6e 2f 30 2e 31 31 2e 31 0d 0a 44 61 74 65 3a 20 n/ 0.11.1..Date: 0030 57 65 64 2c 20 32 30 20 4f 63 74 20 32 30 31 30 Wed, 20 Oct 2010 0040 20 31 36 3a 31 31 3a 31 33 20 47 4d 54 0d 0a 43 16:11:13 GMT..C 0050 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70 2d onnection: keep- 0060 61 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e 74 2d 74 alive..Content- t 0070 79 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e ype: application 0080 2f 6f 63 74 65 74 2d 73 74 72 65 61 6d 0d 0a 43 /octet- stream..C 0090 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 37 ontent-Length: 7 00a0 30 0d 0a 0d 0a 0.... 0000 62 7a 72 20 6d 65 73 73 61 67 65 20 33 20 28 62 bzr message 3 (b 0010 7a 72 20 31 2e 36 29 0a 00 00 00 1c 64 31 36 3a zr 1.6).....d16: 0020 53 6f 66 74 77 61 72 65 20 76 65 72 73 69 6f 6e Software version 0030 35 3a 32 2e 32 2e 31 65 6f 53 73 00 00 00 06 6c 5:2.2.1eoSs....l 0040 32 3a 6f 6b 65 65 2:okee ======================================================= Thanks ! -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
