Noticed some strange behaviour of request.GET.get()

2010-04-07 Thread Alexey Vlasov
Hi.

There's a simple code in urls.py:
==
def ls (request):
import os

out_html = ''
home_path = '/home/www/test-django'
# subdir_path = request.GET.get ('subdir')
subdir_path = 'public_html'

for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)):
out_html += "%s\n" % root

return HttpResponse (out_html)
==

There's a catalogue in "home_path/subdir_path" which name
includes cyrillic symbols (фыва):
$ pwd
/home/www/test-django/public_html
$ ls -la
drwx---r-x  4 test-django test-django  111 Apr  6 20:26 .
drwx--x--- 13 test-django test-django 4096 Apr  6 20:26 ..
-rw-r--r--  1 test-django test-django  201 Apr  6 17:43 .htaccess
-rwxr-xr-x  1 test-django test-django  911 Apr  6 16:38 index.fcgi
lrwxrwxrwx  1 test-django test-django   66 Mar 28 17:34 media -> ../
python/lib64/python2.5/site-packages/django/contrib/admin/media
drwxr-xr-x  2 test-django test-django6 Apr  6 15:48 фыва

My code works correct, here's the result:
$ curl -s http://test-django.example.com/ls/
/home/www/test-django/public_html 
/home/www/test-django/public_html/фыва

But if I change "subdir_path = 'public_html'" to
"subdir_path = request.GET.get ('subdir')" then the request:
$ curl -s http://test-django.example.com/ls/\?subdir=public_html
leads to an error:

Request Method: GET
Request URL: http:// test-django.example.com/ls/
Django Version: 1.0.2 final
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')

Traceback:
File "/home/www/test-django/python/lib64/python2.5/
site-packages/django/core/handlers/base.py" in get_response
  86. response = callback(request, *callback_args, 
**callback_kwargs)
File "/home/www/test-django/django/demo/urls.py" in ls
  40. for root, dirs, files in os.walk (os.path.join (home_path, 
subdir_path)):
File "/usr/lib64/python2.5/os.py" in walk
  293. if isdir(join(top, name)):
File "/usr/lib64/python2.5/posixpath.py" in isdir
  195. st = os.stat(path)

Exception Type: UnicodeEncodeError at /ls/
Exception Value: 'ascii' codec can't encode characters in position
 45-48: ordinal not in range(128)

I don't understand it why "subdir_path" getting the same very value in one case 
works perfectly and in the
+other fails.

Django runs following the instuctions
+http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-wit
+h-apache

--
BRGDS. Alexey Vlasov.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Noticed some strange behaviour of request.GET.get()

2010-04-07 Thread Alexey Vlasov
Hi Bill Freeman.

1. I don't know. Actually I'm not really a django-programmer, I'm only
busy with debugging. But IMHO, in this case it doesn't really matter
where the code is, it should work in urls.py too.

2. subdir_path  u'http'

On Wed, Apr 07, 2010 at 10:16:52AM -0400, Bill Freeman wrote:
> 1.  Why is this view code in urls.py?
> 
> 2.  What is the value of subdir_path in the trace back?  (There's a
> little arrow you can click to
> see the variable values fro the frame.)
> 
> 2010/4/7 Alexey Vlasov :
> > Hi.
> >
> > There's a simple code in urls.py:
> > ==
> > def ls (request):
> >    import os
> >
> >    out_html = ''
> >    home_path = '/home/www/test-django'
> >    # subdir_path = request.GET.get ('subdir')
> >    subdir_path = 'public_html'
> >
> >    for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)):
> >        out_html += "%s\n" % root
> >
> >    return HttpResponse (out_html)
> > ==
> >
> > There's a catalogue in "home_path/subdir_path" which name
> > includes cyrillic symbols (фыва):
> > $ pwd
> > /home/www/test-django/public_html
> > $ ls -la
> > drwx---r-x  4 test-django test-django  111 Apr  6 20:26 .
> > drwx--x--- 13 test-django test-django 4096 Apr  6 20:26 ..
> > -rw-r--r--  1 test-django test-django  201 Apr  6 17:43 .htaccess
> > -rwxr-xr-x  1 test-django test-django  911 Apr  6 16:38 index.fcgi
> > lrwxrwxrwx  1 test-django test-django   66 Mar 28 17:34 media -> ../
> > python/lib64/python2.5/site-packages/django/contrib/admin/media
> > drwxr-xr-x  2 test-django test-django    6 Apr  6 15:48 фыва
> >
> > My code works correct, here's the result:
> > $ curl -s http://test-django.example.com/ls/
> > /home/www/test-django/public_html 
> > /home/www/test-django/public_html/фыва
> >
> > But if I change "subdir_path = 'public_html'" to
> > "subdir_path = request.GET.get ('subdir')" then the request:
> > $ curl -s http://test-django.example.com/ls/\?subdir=public_html
> > leads to an error:
> >
> > Request Method: GET
> > Request URL: http:// test-django.example.com/ls/
> > Django Version: 1.0.2 final
> > Python Version: 2.5.2
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
> >
> > Traceback:
> > File "/home/www/test-django/python/lib64/python2.5/
> > site-packages/django/core/handlers/base.py" in get_response
> >  86.                 response = callback(request, *callback_args, 
> > **callback_kwargs)
> > File "/home/www/test-django/django/demo/urls.py" in ls
> >  40.     for root, dirs, files in os.walk (os.path.join (home_path, 
> > subdir_path)):
> > File "/usr/lib64/python2.5/os.py" in walk
> >  293.         if isdir(join(top, name)):
> > File "/usr/lib64/python2.5/posixpath.py" in isdir
> >  195.         st = os.stat(path)
> >
> > Exception Type: UnicodeEncodeError at /ls/
> > Exception Value: 'ascii' codec can't encode characters in position
> >  45-48: ordinal not in range(128)
> >
> > I don't understand it why "subdir_path" getting the same very value in one 
> > case works perfectly and in the
> > +other fails.
> >
> > Django runs following the instuctions
> > +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-wit
> > +h-apache
> >
> > --
> > BRGDS. Alexey Vlasov.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en.
> >
> >
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
BRGDS. Alexey Vlasov.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Noticed some strange behaviour of request.GET.get()

2010-04-08 Thread Alexey Vlasov
Thanks, subdir_path = str(request.GET.get('subdir')) is what I needed.

I'm grateful to everybody for detailed answers. Thank you.

On Wed, Apr 07, 2010 at 06:59:39PM +0100, Nuno Maltez wrote:
> The only difference I can see is that
> 
> request.GET.get ('subdir')
> 
> will return an unicode string, u"public_html", instead of a normal
> string, 'public_html'.
> 
> 
> If it works with the byte string, try changing the line to
> 
> subdir_path = str(request.GET.get('subdir'))
> 
> Nuno
> 
> 2010/4/7 Alexey Vlasov :
> > Hi.
> >
> > There's a simple code in urls.py:
> > ==
> > def ls (request):
> >    import os
> >
> >    out_html = ''
> >    home_path = '/home/www/test-django'
> >    # subdir_path = request.GET.get ('subdir')
> >    subdir_path = 'public_html'
> >
> >    for root, dirs, files in os.walk (os.path.join (home_path, subdir_path)):
> >        out_html += "%s\n" % root
> >
> >    return HttpResponse (out_html)
> > ==
> >
> > There's a catalogue in "home_path/subdir_path" which name
> > includes cyrillic symbols (фыва):
> > $ pwd
> > /home/www/test-django/public_html
> > $ ls -la
> > drwx---r-x  4 test-django test-django  111 Apr  6 20:26 .
> > drwx--x--- 13 test-django test-django 4096 Apr  6 20:26 ..
> > -rw-r--r--  1 test-django test-django  201 Apr  6 17:43 .htaccess
> > -rwxr-xr-x  1 test-django test-django  911 Apr  6 16:38 index.fcgi
> > lrwxrwxrwx  1 test-django test-django   66 Mar 28 17:34 media -> ../
> > python/lib64/python2.5/site-packages/django/contrib/admin/media
> > drwxr-xr-x  2 test-django test-django    6 Apr  6 15:48 фыва
> >
> > My code works correct, here's the result:
> > $ curl -s http://test-django.example.com/ls/
> > /home/www/test-django/public_html 
> > /home/www/test-django/public_html/фыва
> >
> > But if I change "subdir_path = 'public_html'" to
> > "subdir_path = request.GET.get ('subdir')" then the request:
> > $ curl -s http://test-django.example.com/ls/\?subdir=public_html
> > leads to an error:
> >
> > Request Method: GET
> > Request URL: http:// test-django.example.com/ls/
> > Django Version: 1.0.2 final
> > Python Version: 2.5.2
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
> >
> > Traceback:
> > File "/home/www/test-django/python/lib64/python2.5/
> > site-packages/django/core/handlers/base.py" in get_response
> >  86.                 response = callback(request, *callback_args, 
> > **callback_kwargs)
> > File "/home/www/test-django/django/demo/urls.py" in ls
> >  40.     for root, dirs, files in os.walk (os.path.join (home_path, 
> > subdir_path)):
> > File "/usr/lib64/python2.5/os.py" in walk
> >  293.         if isdir(join(top, name)):
> > File "/usr/lib64/python2.5/posixpath.py" in isdir
> >  195.         st = os.stat(path)
> >
> > Exception Type: UnicodeEncodeError at /ls/
> > Exception Value: 'ascii' codec can't encode characters in position
> >  45-48: ordinal not in range(128)
> >
> > I don't understand it why "subdir_path" getting the same very value in one 
> > case works perfectly and in the
> > +other fails.
> >
> > Django runs following the instuctions
> > +http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-django-on-a-shared-hosting-provider-wit
> > +h-apache
> >
> > --
> > BRGDS. Alexey Vlasov.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at 
> > http://groups.google.com/group/django-users?hl=en.
> >
> >
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

-- 
BRGDS. Alexey Vlasov.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.