Discussion:
[bottlepy] bottle 0.12.11 - redirect error
tomasz bandura
2017-01-07 20:16:09 UTC
Permalink
Hello,

After upgrading to 0.12.11 ( or newer) , I noticed a problem with
forwarding request with any query data.
The example of simple application to reproduce my problem:

[file test.py]
from bottle import route, run, redirect,request

@route('/hello')
def hello():
print 'a1:',request.query.a1
return "Hello World!"

@route('/test')
def test():
a1 = request.query.a1
a2 = request.query.a2
redirect('/hello?a1=%s&a2=%s' % (a1,a2))

run(host='localhost', port=8080, debug=True)

When I try to invoke for example link:
http://localhos:8080/test?a1=123&a2=456 , bottle raises an exception:


Critical error (...)
AssertionError('Header values must be strings',)

Traceback:
Traceback (most recent call last): File
"(...)/python/bottle/test/venv/lib/python2.7/site-packages/bottle.py", line
960, in wsgi start_response(response._status_line, response.headerlist)
File "/usr/lib64/python2.7/wsgiref/handlers.py", line 180, in
start_response assert type(val) is StringType,"Header values must be
strings" AssertionError: Header values must be strings

I also checked it on Windows OS - the same error.

This example works correctly with bottle 0.12.10 and older.
Is something wrong in my redirect or is there any other method to make
redirect with query data?


Regards,
Tomasz
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
tomasz bandura
2017-01-11 13:46:58 UTC
Permalink
I have received a response from Michiel Overtoom directly (thank you!):

I have investigated a bit. [I tried posting to the google group, but it
wouldn't let me, so I sent it to you. Maybe you can post it on the mailing
list].

In bottle.py, in start_response(), the passed 'headers' parameter contains
this:

[('Content-Length', '0'), ('Location', u'
http://localhost:8080/hello?a1=123&a2=456'), ('Content-Type', 'text/html;
charset=UTF-8')]

Note that the value of the 'Location' header is an unicode string.

Apparently, an unicode string is not a StringType:

Python 2.7.10 (default, Jul 14 2015, 19:46:27)
Post by tomasz bandura
from types import StringType
u"Hallo" is StringType
That's why start_response() in wsgiref/handlers.py throws an exception on
the line:

assert type(val) is StringType,"Header values must be strings"

To fix it, I think bottle.py must automatically convert header values from
unicode to strings.

Greetings,


But now it looks the last release of bottle (0.12.13) fixed this problem.

Tomasz



W dniu sobota, 7 stycznia 2017 21:16:10 UTC+1 uÅŒytkownik tomasz bandura
Post by tomasz bandura
Hello,
After upgrading to 0.12.11 ( or newer) , I noticed a problem with
forwarding request with any query data.
[file test.py]
from bottle import route, run, redirect,request
@route('/hello')
print 'a1:',request.query.a1
return "Hello World!"
@route('/test')
a1 = request.query.a1
a2 = request.query.a2
redirect('/hello?a1=%s&a2=%s' % (a1,a2))
run(host='localhost', port=8080, debug=True)
Critical error (...)
AssertionError('Header values must be strings',)
Traceback (most recent call last): File
"(...)/python/bottle/test/venv/lib/python2.7/site-packages/bottle.py", line
960, in wsgi start_response(response._status_line, response.headerlist)
File "/usr/lib64/python2.7/wsgiref/handlers.py", line 180, in
start_response assert type(val) is StringType,"Header values must be
strings" AssertionError: Header values must be strings
I also checked it on Windows OS - the same error.
This example works correctly with bottle 0.12.10 and older.
Is something wrong in my redirect or is there any other method to make
redirect with query data?
Regards,
Tomasz
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...