os.path.exists behaves differently if called from a django app.  Why?
Can I work around this?  I need to check if pathnames exist where the
path may have special/unicode characters.  I also need to open files
from that path.

The path in this demo contains "El CamarĂ³n de la Isla", where the
accent character is the trouble maker.

Any help is really appreciated.

-----------------------------------------------------------------------------------------------------
Contents of demo.py
-----------------------------------------------------------------------------------------------------

[EMAIL PROTECTED]:/home/published/www/django/catalog/music# cat demo.py

import os
import music.models as model

def checkpath():
        album = model.Album.objects.get(slug='como-al-agua')

        return os.path.exists(album.folderpath)

-----------------------------------------------------------------------------------------------------
Calling checkpath() function in demo.py from the command interpreter
-----------------------------------------------------------------------------------------------------

[EMAIL PROTECTED]:/home/published/www/django/catalog# python

Python 2.5.2 (r252:60911, Oct  5 2008, 19:24:49)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> import music.demo
>>> music.demo.checkpath()
True
>>>

-----------------------------------------------------------------------------------------------------
Finally, what happens when called from a Django application.
You can see that I call checkpath in demo.py
Code fails in posixpath.py when doing os.stat(path)
-----------------------------------------------------------------------------------------------------

'ascii' codec can't encode character u'\xf3' in position 35: ordinal
not in range(128)

Request Method:         GET
Request URL:    http://music.sensiblestaffing.com/music/cover/como-al-agua/
Exception Type:         UnicodeEncodeError
Exception Value:

'ascii' codec can't encode character u'\xf3' in position 35: ordinal
not in range(128)

Exception Location:     /usr/lib/python2.5/posixpath.py in exists, line
171
Python Executable:      /usr/bin/python
Python Version:         2.5.2

#  /home/published/www/django/catalog/music/extended.py in Cover


  54. result = music.demo.checkpath() ...


# /usr/lib/python2.5/posixpath.py in exists


 171. st = os.stat(path) ...



--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to