1
我輸入了:「python manage.py loaddata fixtures \ companies.json」。它給了我一個錯誤。如何將燈具上傳到gae數據存儲?
什麼是加載json數據然後將其推送到gae數據存儲的正確方法?
這裏是我的模型:
class Company(models.Model):
id = models.AutoField(primary_key=True);
name = models.CharField(max_length=100);
address = models.CharField(max_length=100, null=True);
city = models.CharField(max_length=100);
state = models.CharField(max_length=25);
zip = models.IntegerField();
latitude = models.CharField(max_length=20, null=True)
longitude = models.CharField(max_length=20, null=True)
phone = models.CharField(max_length=15, null=True);
website = models.CharField(max_length=50, null=True);
email = models.EmailField(max_length=50, null=True);
hiring = models.BooleanField(default=False);
approved = models.BooleanField(default=False);
date_added = models.DateTimeField(auto_now_add=True);
about_us = models.TextField(max_length=500, null=True);
這裏是我的燈具:
[
{
"model": "Companies.Company",
"fields": {
"id": 111,
"name": "1-800 Postcards America's Printing Company",
"address": "121 Varick Street, 7th Floor",
"city": "New York",
"state": "NY",
"zip": 10013,
"latitude": "40.724831999999999",
"longitude": "-74.00609",
"phone": "212-741-1070",
"website": "http://www.1800postcards.com",
"email": "[email protected]",
"hiring": "FALSE",
"approved": "TRUE",
"date_added": "April 30, 2012, 6:08 p.m.",
"about_us": "With over 30 years of business experience as full service offset printers and over 200 years of combined knowledge in our production department and press rooms, 1-800Postcards is your professional printer. Our state-of-the-art 125,000 square foot facility is located in the heart of New York City, with an additional web offset plant in New Jersey for our larger orders 500,000 and up. This makes it possible for us to print and mail the highest quality postcards on the market today — at the most competitive rates in the country."
}
},
{
"model": "Companies.Company",
"fields": {
"id": 222,
"name": "20x200 ",
"address": "6 Spring Street",
"city": "New York",
"state": "NY",
"zip": 10012,
"latitude": "40.721052999999998",
"longitude": "-73.994322999999994",
"phone": "212-219-0166",
"website": "http://www.20x200.com/",
"email": "[email protected]",
"hiring": "TRUE",
"approved": "TRUE",
"date_added": "April 30, 2012, 6:08 p.m.",
"about_us": "(limited editions × low prices) + the internet = art for everyone. That simple formula, devised by 20x200's founder, Jen Bekman, is what launched 20x200 back in 2007. With that, we set our sights on two core goals: We want everyone to collect art, and we want to enable an economy that allows more artists to make a living by making work. More so, we wanted something as awesome as collecting art to be fun. That's right: fun!"
}
},
{
"model": "Companies.Company",
"fields": {
"id": 333,
"name": "Adafruit",
"address": "80 Nassau st #4C",
"city": "New York",
"state": "NY",
"zip": 10038,
"latitude": "40.709938000000001",
"longitude": "-74.007987999999997",
"phone": "646-248-7822",
"website": "http://www.adafruit.com/",
"email": "N/A",
"hiring": "TRUE",
"approved": "TRUE",
"date_added": "April 30, 2012, 6:08 p.m.",
"about_us": "We pride ourselves on having great prices, the best customer service, support and fast shipping. We hope we can assist you on your journey of learning – At Adafruit we celebrate 「Engineering Happiness」! Adafruit is a 100% Woman-Owned Small Business."
}
}
]
這裏是我的錯誤:
Problem installing fixture 'fixtures\companies.json': Traceback (most recent call last):
File "C:\Users\Joe\Desktop\My School Stuff\Spring 2012\CS 473\ny-tech\ny-tech\django\core\management\commands\loaddata.py", line 169, in handle
for obj in objects:
File "C:\Users\Joe\Desktop\My School Stuff\Spring 2012\CS 473\ny-tech\ny-tech\django\core\serializers\json.py", line 35, in Deserializer
for obj in PythonDeserializer(simplejson.load(stream), **options):
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\__init__.py", line 332, in load
use_decimal=use_decimal, **kw)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\__init__.py", line 388, in loads
return _default_decoder.decode(s)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\decoder.py", line 402, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\decoder.py", line 418, in raw_decode
obj, end = self.scan_once(s, idx)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\scanner.py", line 71, in scan_once
return _scan_once(string, idx)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\scanner.py", line 44, in _scan_once
return parse_array((string, idx + 1), _scan_once)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\decoder.py", line 284, in JSONArray
value, end = scan_once(s, end)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\scanner.py", line 42, in _scan_once
_scan_once, object_hook, object_pairs_hook, memo)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\decoder.py", line 230, in JSONObject
value, end = scan_once(s, end)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\scanner.py", line 42, in _scan_once
_scan_once, object_hook, object_pairs_hook, memo)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\decoder.py", line 230, in JSONObject
value, end = scan_once(s, end)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\scanner.py", line 39, in _scan_once
return parse_string(string, idx + 1, encoding, strict)
File "C:\Program Files (x86)\Google\google_appengine\lib\simplejson\simplejson\decoder.py", line 121, in py_scanstring
content = unicode(content, encoding)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x97 in position 484: invalid start byte
Exception AttributeError: "'NoneType' object has no attribute 'mkstemp'" in <bound method DatastoreFileStub.__del__ of <google.appengine.api.datastore_file_stub
.DatastoreFileStub object at 0x02930F10>> ignored
你能確保你的JSON有效嗎?將以上內容複製並粘貼到jsonlint.com中會產生錯誤。此外,0x97引用了em破折號( - ),雖然我不知道爲什麼它的包含會導致問題,但可以嘗試從JSON中刪除它。 –
@DanHolevoet我看到錯誤,我搞砸了TRUE/FALSE fieldss,感謝jsonlint,從來不知道有這樣的事情! – iCodeLikeImDrunk
很高興聽到它現在正在工作。對於這類問題的其他人,我發佈了以下答案。 –