Im пытается загрузить прибор, который выглядит следующим образом:Джанго: 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()
И я загружаю светильник из ЦМД, как это:
python manage.py loaddata some_filename.json
значения и ключи, кажется, хорошо для меня. Во всем json нет пустых значений. Что может быть неправильно? Спасибо :)
как вы получите файл в формате JSON? и как вы попытались загрузить его? – shellbye
@shellbye: обновлено. – mohit