Django

Code

Ticket #5281 (closed: wontfix)

Opened 2 years ago

Last modified 2 years ago

Non unicode GET-data is not allowed?

Reported by: bjorn.kempen@gmail.com Assigned to: nobody
Milestone: Component: HTTP handling
Version: SVN Keywords: unicode GET
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I try access my domain and pass the escaped URL-character for for an example 238 which is %EE This is of course just an example. My actual implementation has longer values
http://mydomain.com/?info_hash=%EE

In my view I do something like this

def handle_stuff(request):
  get_data = request.GET.copy()
  info_hash = get_data["info_hash"]
  assert(False) # for debugging

The relevant debug info
get_data == <MultiValueDict?: {u'info_hash': [u'\ufffd']}>
info_hash == u'\ufffd'

\ufffd is the error character in unicode, so basically standard URL escaped arguments as GET does not work in django as of the unicode branch.

This makes it impossible to interface with any external application that uses this. In my case I was writing a bittorrent tracker, and bittorrent uses non unicode GET-data for it's transmissions. In other words... until this is fixed, using django as a bittorrent tracker is impossible, as well as interfacing django with any other application that uses standard url escaped characters as GET-data.

Attachments

Change History

09/14/07 17:26:50 changed by frej

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Using request.encoding = 'latin-1' from current svn should fix this.

09/15/07 09:07:29 changed by Fredrik Lundh <fredrik@pythonware.com>

  • status changed from new to closed.
  • resolution set to wontfix.

As frej says, setting the encoding to "latin-1" (or "iso-8859-1" if you want to get fancy) will fix this. You'll still the bytes as a Unicode string; do u.encode("iso-8859-1") to get back the original raw string.

Closing this as "wontfix" for now (a "wontfix; workaround provided" would be nice ;-)

(follow-up: ↓ 4 ) 03/15/08 16:15:22 changed by Dorian Grey <imgrey@gmail.com>

  • status changed from closed to reopened.
  • resolution deleted.

request.encoding = 'latin-1' not working, request.GET is still <type 'unicode'>

(in reply to: ↑ 3 ; follow-up: ↓ 5 ) 03/15/08 17:23:29 changed by ubernostrum

  • status changed from reopened to closed.
  • resolution set to wontfix.

Replying to Dorian Grey <imgrey@gmail.com>:

request.encoding = 'latin-1' not working, request.GET is still <type 'unicode'>

Yes, actually read what Fredrik wrote about what you need to do.

(in reply to: ↑ 4 ) 03/16/08 05:33:11 changed by Dorian Grey <imgrey@gmail.com>

Replying to ubernostrum:

Replying to Dorian Grey <imgrey@gmail.com>:

request.encoding = 'latin-1' not working, request.GET is still <type 'unicode'>

Yes, actually read what Fredrik wrote about what you need to do.

perhaps curious minds want to know a solution to this problem for the current revision.

1. remove slash aftrer 'announce' in urls.py 2. request.GETinfo_hash?.encode('iso-8859-1').encode('hex')

I was trying to close this myself, but code.djangoproject.com answered "Internal Server Error"


Add/Change #5281 (Non unicode GET-data is not allowed?)




Change Properties
Action