Karen, Thanks for the response, but I'm unable to unquote the strings as django does it automatically for me when I get the GET list entries.
I've tried to run it from django, insert an assert false and give you the answer Here's the URL that was entered: http://127.0.0.1:8000/announce/?info_hash=%EByXm%C5%7EmfD%D8%9A%91%D4%F7%C7%86%C7%D18%A7&peer_id=-TR1210-1q4q9aomcne9&port=51413&uploaded=0&downloaded=0&corrupt=0&left=0&compact=1&numwant=80&key=jda2jjrygr&event=started Here's the URL handler def view_announce(request): # request.encoding = "iso-8859-1" request.encoding = "latin-1" #client information c = {} try: #if the client explicitly specifies its preferred IP address, then #use that. Else just take the address. c['addr'] = request.GET.get('ip', None) or request.META['REMOTE_ADDR'] c['port'] = int(request.GET['port']) c['peer_id'] = request.GET['peer_id'] # JFM, hack arond unicode issues with info_hash in django hash = request.GET['info_hash'].encode('iso8859-1') except KeyError: #if any of these is not defined, then it makes little sense to proceed. return _fail("""One of the following is missing: IP, Port, Peer_ID or info_hash""") print "Got all keys..." print "hash " + hash assert False Here's the dump from Assert false: Request information GET Variable Value uploaded u'0' compact u'1' numwant u'80' info_hash u'\xebyXm\xc5~mfD\xd8\x9a\x91\xd4\xf7\xc7\x86\xc7\xd18\xa7' event u'started' downloaded u'0' key u'jda2jjrygr' corrupt u'0' peer_id u'-TR1210-1q4q9aomcne9' port u'51413' left u'0' POST No POST data COOKIES Variable Value sessionid 'f356ef76d6c20c3be39aec3d29ff023a' META Variable Value Apple_PubSub_Socket_Render '/tmp/launch-1GTNEW/Render' COMMAND_MODE 'unix2003' CONTENT_LENGTH '' CONTENT_TYPE 'text/plain' DISPLAY '/tmp/launch-eJizQ9/:0' DJANGO_SETTINGS_MODULE 'tracker.settings' GATEWAY_INTERFACE 'CGI/1.1' HOME '/Users/John' HTTP_ACCEPT 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/ plain;q=0.8,image/png,*/*;q=0.5' HTTP_ACCEPT_ENCODING 'gzip, deflate' HTTP_ACCEPT_LANGUAGE 'en-us' HTTP_CACHE_CONTROL 'max-age=0' HTTP_CONNECTION 'keep-alive' HTTP_COOKIE 'sessionid=f356ef76d6c20c3be39aec3d29ff023a' HTTP_HOST '127.0.0.1:8000' HTTP_USER_AGENT 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; en-us) AppleWebKit/ 525.18 (KHTML, like Gecko) Version/3.1.1 Safari/525.18' LANG 'en_US.UTF-8' LOGNAME 'John' MANPATH '/usr/share/man:/usr/local/share/man:/usr/X11/man' OLDPWD '/Users/John/development' PATH '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin' PATH_INFO '/announce/' PWD '/Users/John/development/tracker' QUERY_STRING 'info_hash=%EByXm%C5%7EmfD%D8%9A%91%D4%F7%C7%86%C7%D18%A7&peer_id=- TR1210-1q4q9aomcne9&port=51413&uploaded=0&downloaded=0&corrupt=0&left=0&compact=1&numwant=80&key=jda2jjrygr&event=started' REMOTE_ADDR '127.0.0.1' REMOTE_HOST '' REQUEST_METHOD 'GET' RUN_MAIN 'true' SCRIPT_NAME '' SECURITYSESSIONID '6939d0' SERVER_NAME 'localhost' SERVER_PORT '8000' SERVER_PROTOCOL 'HTTP/1.1' SERVER_SOFTWARE 'WSGIServer/0.1 Python/2.5.1' SHELL '/bin/bash' SHLVL '1' SSH_AUTH_SOCK '/tmp/launch-qjIQx5/Listeners' TERM 'xterm-color' TERM_PROGRAM 'Apple_Terminal' TERM_PROGRAM_VERSION '240' TMPDIR '/var/folders/v-/v-IkkU9PHbeIn98mRd6ZM++++TI/-Tmp-/' TZ 'America/Los_Angeles' USER 'John' _ './manage.py' __CF_USER_TEXT_ENCODING '0x1F5:0:0' wsgi.errors <open file '<stderr>', mode 'w' at 0x170b0> wsgi.file_wrapper <class 'django.core.servers.basehttp.FileWrapper'> wsgi.input <socket._fileobject object at 0x6d5bb0> wsgi.multiprocess False wsgi.multithread True wsgi.run_once False wsgi.url_scheme 'http' wsgi.version (1, 0) john On May 29, 7:04 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > On Thu, May 29, 2008 at 3:54 AM, John M <[EMAIL PROTECTED]> wrote: > > > I've run into some more trouble with what I think is an encoding > > issue? > > > I am writting a bittorrent tracker, and one of the GET parameters that > > is passed is called info_hash, which is a lengthy / escaped hex > > string, for example: > > > GET /announce?info_hash=%EByXm%C5%7EmfD%D8%9A%91%D4%F7%C7%86%C7%D18%A7 > > > the django / python code I am using to decode this is: > > > request.encoding = "iso-8859-1" > > hash = request.GET['info_hash'].encode('iso-8859-1').encode("hex") > > > But when I print the hash field, i get this: > > > efbfbd6defbfbd6d6644d89aefbfbdefbfbdc786efbfbd38efbfbd > > > where it should be > > > eb79586dc57e6d6644d89a91d4f7c786c7d138a7 > > > I had it working for a while, but I'm not sure what changed to 'break' > > this. > > > Any help would be greatly appreciated > > First, the code you've included doesn't produce the answer you show, so I'm > a little confused about what your code is really doing. In a python shell: > > >>> s = '%EByXm%C5%7EmfD%D8%9A%91%D4%F7%C7%86%C7%D18%A7' > >>> s.encode('iso8859-1').encode('hex') > > '25454279586d2543352537456d664425443825394125393125443425463725433725383625433725443138254137' > > Where the 'efbbd...' is coming from I don't understand. But doing anything > with an encoding like iso8859-1 isn't what you want to do anyway. You just > want to un-do the percent-encoding and convert (encode) into the hex > representation, using just the plain ASCII values for anything that wasn't > percent-encoded: > > >>> urllib.unquote(s).encode('hex') > > 'eb79586dc57e6d6644d89a91d4f7c786c7d138a7' > > so try: > > import urllib > hash = urllib.unquote(request.GET['info_hash']).encode('hex') > > Karen --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---