I have some lovely (Scandinavian?) user on my website complaining that I cannot parse his username in URLs, and hence I am showing him no results on his page on my website.
I am pretty sure that the browser encodes the requests as
http://councilroom.com/player?player=G%C3%B6rling
I’d like to get the player string to become Görling rather than Görling that is getting converted to.
I am using web.py with python 2.6 and attempting to parse the URL as follows
parsed_url = urlparse.urlparse(web.ctx.fullpath)
query_dict = dict(urlparse.parse_qsl(parsed_url.query))
target_player = query_dict['player']
Edit: With the help of unutbu, I fixed this by changing it to
query_dict = dict(urlparse.parse_qsl(web.ctx.env['QUERY_STRING']))
target_player = query_dict['player'].decode('utf-8')
I think webpy was mis-parsing the fullpath in web.ctx somehow, but the QUERY_STRING variable is unmolested.
Note the
.decode('utf-8'):PS. Somehow, the bytes in the
strobject'G\xc3\xb6rling'were being interpreted as a sequence of unicode code points, with the effect of turningGörlingintoGörling: