1

I'm trying to dumpdata into a file, and keep getting this error:

d:\django\mysite>manage.py dumpdata > alldata.json
Traceback (most recent call last):
  File "D:\django\mysite\manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 241, in execute
    self.stdout.write(output)
IOError: [Errno 9] Bad file descriptor

I have a feeling this has something to do with codepage or unicode. Trying executing this in PowerShell, and there was no error, but the data was PRINTED to the screen and the file was empty... (as if the > sign wasn't there).

Anyone has any idea what could cause this?

Thanks in advance :)

Moti Radomski
  • 275
  • 2
  • 8
  • Your `Bad file descriptor` message is coming from the Python code, so it appears it's encountering that error before or perhaps during the output setup. If the `> alldata.json` was the problem, you'd see the error come from the shell. I suggest you try running the command without the `>` to see where that error occurs. – akraut Oct 03 '12 at 20:32
  • Thanks. Running with the > redirection doesn't cause any error. The data is simply printed on the screen. See the answer below, this has something to do with executing the script directly on the command prompt. – Moti Radomski Oct 04 '12 at 04:27

1 Answers1

3

If I am not wrong, you are using

manage.py dumpdata

try to use it like this

python manage.py dumpdata

It should work.

Thanks

Paritosh Singh
  • 6,288
  • 5
  • 37
  • 56
  • Thanks!! That did the trick! Can you please explain the difference between the two methods? – Moti Radomski Oct 03 '12 at 18:23
  • 1
    @MotiRadomski its simple, using python command in before filename means to execute it using python interpreter. Django is a framework written in python. – Paritosh Singh Oct 04 '12 at 01:56
  • Thanks. Sure, but what's the difference between running c:\>myscript.py and c:\>python myscript.py? In my win registry, I see .py files are registered to python.exe anyway... strange stuff :) – Moti Radomski Oct 04 '12 at 04:25
  • oh you are using windows, sry i am a linux user :) – Paritosh Singh Oct 04 '12 at 04:36
  • If this worked, that means the `python` executable on your shell's PATH is different from the default python executable associated with `.py` files, so when you explicitly tell it to use python to run the manage.py command, you are telling it to use the one found on your shell's PATH. – Daniel Hawkins Apr 22 '15 at 15:23