7 Replies - 304 Views - Last Post: 14 May 2013 - 03:42 PM Rate Topic: -----

#1 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7572
  • View blog
  • Posts: 12,717
  • Joined: 19-March 11

django manage.py failing on locale.getdefaultlocale()

Posted 13 May 2013 - 12:41 PM

This is known issue, but I haven't found a solution that's worked yet. Any suggestions would be useful.

I'm tring to bang together a quick django front end for a tool I've made at work, but when I try to use the manage.py script, it's failing to recover a locale from locale.getdefaultlocal() (it's getting (None, None))

I've tried the fixes suggested in the top search results - the LANG env variable is set (LANG='en_US.UTF-8') and putting in a line to explicitly set locale in the manage.py script didn't help.

I can get things working if I install django 1.1.1, but it fails on 1.4.3 (apparently the bug was introduced relatively recently). Anyone got any suggested workarounds, or do I have to fall back to 1.1.1? That wouldn't be the end of the world, but it would be nice to be able to be up to the current release if that's possible.

Any thoughts on how to get locale.getdefaultlocale() to return a good value for the manage.py script?

Possibly relevant: we're running ubuntu 10.04 at my office, due to factors beyond my control. It's possible that being behind days on the ubuntu version is a contributing factor, but I don't know how.

Is This A Good Question/Topic? 0
  • +

Replies To: django manage.py failing on locale.getdefaultlocale()

#2 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: django manage.py failing on locale.getdefaultlocale()

Posted 13 May 2013 - 06:44 PM

I haven't used Django for a couple of years now probably, and never had this error since it was before 1.4.3 anyway. This may be something you've already tried.. but let's see.

When you put "in a line to explicitly set locale in the manage.py script" was it:
os.environ.setdefault('LANG','en_US')

also:
locale.setlocale(LC_ALL, '')

Lets it use the default locale as defined by the LANG variable. (Python docs)

There is a set locale in the locale module, and default one in the os module, and perhaps some other places. Try sticking one of those (if you haven't) at the top of manage.py.

This post has been edited by Simown: 13 May 2013 - 06:47 PM

Was This Post Helpful? 0
  • +
  • -

#3 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7572
  • View blog
  • Posts: 12,717
  • Joined: 19-March 11

Re: django manage.py failing on locale.getdefaultlocale()

Posted 14 May 2013 - 10:37 AM

Yeah, tried both of those. Also, noticed the line

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "kankan.settings")

in manage.py, so I tried messing about with settings.py, setting variations on LANG='en_US' and so forth - no joy there, either.


I'm not sure if django is even the best way to do what I'm after - I have some python that I use to update our various dev environments from the repository, using pysvn and pysmbclient. Nothing very fancy, but it works nicely. Some of the other developers want a front end for it, which is reasonable, so I figured I'd try django. So far, it's been a little frustrating, but that's what learning is sometimes.
Was This Post Helpful? 0
  • +
  • -

#4 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: django manage.py failing on locale.getdefaultlocale()

Posted 14 May 2013 - 11:38 AM

I figured you might have tried that :) Don't think I can offer much more light on it right now.

I really like working with Django, if you have a Python backend I'd definitely say Django was a good candidate for working with it over other web frameworks anyway. Hopefully it will all work out, I'd be interested to know what the fix was.

Edit: I found this blogpost about locale error in manage.py, but a different part. Their solution was to export the locale variables in the environment instead of in the Python files.

This post has been edited by Simown: 14 May 2013 - 11:39 AM

Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7572
  • View blog
  • Posts: 12,717
  • Joined: 19-March 11

Re: django manage.py failing on locale.getdefaultlocale()

Posted 14 May 2013 - 01:36 PM

Not a fix, but I've found a workaround: turning off internationalization and localization seems to have got me past this issue. Which makes sense, and I'm embarrassed that I didn't think of it before...


Quote

Edit: I found this blogpost about locale error in manage.py, but a different part.

I did try something like that solution, but I might go back and have another look at it.

For now, I can move forward on trying to solve my actual problem, which is making this front end...

Thanks for your thoughts on this one!


EDIT: Derp. It worked because I was working in the wrong terminal, on the machine that was already working under version 1.1.1.
Back to the drawing board...

This post has been edited by jon.kiparsky: 14 May 2013 - 01:41 PM

Was This Post Helpful? 0
  • +
  • -

#6 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: django manage.py failing on locale.getdefaultlocale()

Posted 14 May 2013 - 02:13 PM

Is there a downside to downgrading back to 1.1.1 if it works? Or perhaps get it working under 1.1.1 first and then try and get it working under 1.4.3. Fortunately, they list most backwards incompatible feature in the changelogs when a new version is released (I think), so it may just be a case of scouring them and tweaking if you went that way.

Good luck with that.
Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7572
  • View blog
  • Posts: 12,717
  • Joined: 19-March 11

Re: django manage.py failing on locale.getdefaultlocale()

Posted 14 May 2013 - 03:31 PM

Stupid of me. Just installed 1.5.1. The bug is no longer present. Happy day.
Was This Post Helpful? 0
  • +
  • -

#8 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 319
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: django manage.py failing on locale.getdefaultlocale()

Posted 14 May 2013 - 03:42 PM

Huzzah! If only "wait for someone else to fix the bug" was always the answer :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1