我試着加載夾具,看起來像這樣:Django的:ValueError異常的承載夾具
some_filename.json
[
{
"fields": {
"blockName": "Home & Tech",
"catName": "Home",
"catUrl": "http://www.buyam.com.ng/catalog/home/35",
"prodDesc": "Jojo Pet food is made with added nutrition to meet the demands of a grown up dog that's highly active and needs loads of energy and nutrition. By gaining the required energy with this food, dogs can live life to the optimum. This food can prove to be better as it gives dogs the required blend of fibers that can keep the stomach healthy and the patented X-shaped kibbles that are good to maintain clean and strong teeth till the gum line.",
"prodName": "Jo-Jo Dog Food - Tripe Mix 400g",
"prodTypeName": "Pet Supplies",
"prodTypeUrl": "http://www.buyam.com.ng/catalog/pet-supplies/419",
"prodUrl": "http://www.buyam.com.ng/catalog/pet-supplies/419/jo-jo-dog-food-tripe-mix-400g"
},
"model": "kudisavers.product",
"pk": 1
},
{
...
...
}
]
,但我得到了以下錯誤:
Traceback (most recent call last):
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\serializers\json.py", line 74, in Deserializer
objects = json.loads(stream_or_string)
File "C:\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "C:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\management\base.py", line 338, in execute
output = self.handle(*args, **options)
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\management\commands\loaddata.py", line 61, in handle
self.loaddata(fixture_labels)
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\management\commands\loaddata.py", line 91, in loaddata
self.load_label(fixture_label)
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\management\commands\loaddata.py", line 142, in load_label
for obj in objects:
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\serializers\json.py", line 81, in Deserializer
six.reraise(DeserializationError, DeserializationError(e), sys.exc_info()[2])
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\utils\six.py", line 549, in reraise
raise value.with_traceback(tb)
File "D:\MyWork\Python\Django_Projects\VirtualEnv\lib\site-packages\django\core\serializers\json.py", line 74, in Deserializer
objects = json.loads(stream_or_string)
File "C:\Python34\lib\json\__init__.py", line 318, in loads
return _default_decoder.decode(s)
File "C:\Python34\lib\json\decoder.py", line 343, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
raise ValueError(errmsg("Expecting value", s, err.value)) from None
django.core.serializers.base.DeserializationError: Problem installing fixture 'D:\MyWork\Python\Django_Projects\kudisavers\fixtures\buyam-fixture.json': Expecting value: line 1 column 1 (char 0)
這是我創建json的方式:
file = open('some_filename.json', 'wb')
file.write(json.dumps(data, sort_keys=True, indent=4))
file.close()
我從CMD加載夾具是這樣的:
python manage.py loaddata some_filename.json
值和鍵似乎好了給我。整個JSON沒有空白值。 什麼可能是錯誤的? 謝謝:)
你怎麼JSON文件?你是如何加載它的? – shellbye 2014-12-02 11:30:58
@shellbye:已更新。 – mohit 2014-12-02 11:34:32