8

I have put down a Django project I was working on for a couple months, when I attempted to re run the server I got this error:

ValueError: source code string cannot contain null bytes

The Traceback is:

C:\Users\Broja\Desktop\mynewenv\computersite>manage.py runserver
Traceback (most recent call last):
  File "C:\Users\Broja\Desktop\mynewenv\computersite\manage.py", line 8, in 
<module>
    from django.core.management import execute_from_command_line
  File "C:\Users\Broja\AppData\Local\Programs\Python\Python35\lib\site-
 packages\django\__init__.py", line 3, in <module>
     from django.utils.version import get_version
ValueError: source code string cannot contain null bytes

I am not too familiar with the Django Framework so this error confuses me, any help would go a long way. Thanks.

6
  • 1
    Somehow there are embedded null bytes in your python script. Did you open it with a different editor? Commented Sep 15, 2017 at 23:20
  • Yes I was originally working on it with PyCharm then I experimented with IntelliJ IDEA stupidly to no success then went back to PyCharm Commented Sep 15, 2017 at 23:21
  • Well, if IntelliJ created the problem, maybe it can fix it too. Does it have an option to save files as binary? Commented Sep 15, 2017 at 23:26
  • Not that I know of but how would that help? And how would that also affect the HTML in my templates folder? Commented Sep 15, 2017 at 23:28
  • If there is an option to save your python script as binary, then you could try turning that option off and re-saving the file. Commented Sep 15, 2017 at 23:34

2 Answers 2

16

Just convert it to UTF-8. That worked for me :)

Sign up to request clarification or add additional context in comments.

2 Comments

I had the same problem using Sublime 3 as editor. It got solved if I resaved the models.py file in my app folder as 'Save with Encoding :: UTF-8'.
Could you please tell me how exactly to convert to UTF-8? Thank you very much.
3

Anyone who is looking for a simple solution in windows OS. Just edit the target file(the file which is causing the issue) in Notepad.

  1. Click File.
  2. Click Save As.
  3. Along the Save Button, there is an option for Encoding, just select UTF-8 and select All Files option from the Save As Type option and enjoy

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.