Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google应用程序引擎数据导出到CSV TextProperty_Python_Google App Engine_Export To Excel_Export To Csv_Google App Engine Python - Fatal编程技术网

Python Google应用程序引擎数据导出到CSV TextProperty

Python Google应用程序引擎数据导出到CSV TextProperty,python,google-app-engine,export-to-excel,export-to-csv,google-app-engine-python,Python,Google App Engine,Export To Excel,Export To Csv,Google App Engine Python,因此,我在我的Google应用程序引擎(Python)中有一个textproperty变量。我正在通过远程api将数据导出到csv import csv class Tower_of_London_History(db.Model): email = db.StringProperty(required=True) start_datetime = db.DateTimeProperty(required=True) end_datetime = db.DateTimeP

因此,我在我的Google应用程序引擎(Python)中有一个textproperty变量。我正在通过远程api将数据导出到csv

import csv
class Tower_of_London_History(db.Model):
    email = db.StringProperty(required=True)
    start_datetime = db.DateTimeProperty(required=True)
    end_datetime = db.DateTimeProperty(required=True)
    duration_to_first_move = db.IntegerProperty(required=True)
    completed = db.BooleanProperty(required=True)
    tower_type = db.StringProperty(required=True)
    duration = db.IntegerProperty(required=True)
    total_violations = db.IntegerProperty(required=True)
    total_legal_moves = db.IntegerProperty(required=True)
    time_type = db.StringProperty(required=True)
    move_time_stamps = db.TextProperty(required=True)
    timezone = db.StringProperty(required=False)
    utc_to_local_delta = db.IntegerProperty(required=False)

def exportToCsvTower_of_London_History(query, csvFileName, delimiter):
    with open(csvFileName, 'wb') as csvFile:
        csvWriter = csv.writer(csvFile, delimiter=delimiter, quotechar='|', quoting=csv.QUOTE_MINIMAL)
        writeHeaderTower_of_London_History(csvWriter)

        rowsPerQuery = 1000
        totalRowsSaved = 0
        cursor = None
        areMoreRows = True

        while areMoreRows:
            if cursor is not None:
                query.with_cursor(cursor)
            items = query.fetch(rowsPerQuery)
            cursor = query.cursor()

            currentRows =0
            for item in items:
                saveItemTower_of_London_History(csvWriter, item)
                currentRows += 1

            totalRowsSaved += currentRows
            areMoreRows = currentRows >= rowsPerQuery
            print 'Saved ' + str(totalRowsSaved) + ' rows'

        print 'Finished saving all rows.'

def writeHeaderTower_of_London_History(csvWriter):
    csvWriter.writerow(['email', 'start_datetime', 'end_datetime', 'duration_to_first_move (seconds)', 'completed',
                        'tower_type', 'duration (seconds)', 'total_violations', 'total_legal_moves', 'time_type',
                        'move_time_stamps', 'timezone', 'utc_to_local_delta (mins)']) #Output csv header

def saveItemTower_of_London_History(csvWriter, item):
    csvWriter.writerow([item.email, item.start_datetime, item.end_datetime, item.duration_to_first_move, 
                        item.completed, item.tower_type, item.duration, item.total_violations, item.total_legal_moves,
                        item.time_type, item.move_time_stamps, item.timezone, item.utc_to_local_delta]) # Save items in preferred format

query = Tower_of_London_History.gql("ORDER BY email")
exportToCsvTower_of_London_History(query, 'moment_exported_csv_files/tower_of_london_history.csv', ',')
我得到以下错误

BadValueError: Property move_time_stamps is 3085 bytes long; it must be 1500 or less.
供您参考,我使用以下方法运行该程序: (在航站楼上) 远程应用程序ID 导入文件名

我想知道是否有任何方法可以将大于1500字节的TextProperty导出到Excel CSV

这是完整的追踪

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "export_moment_data.py", line 568, in <module>
    exportToCsvTower_of_London_History(query, 'moment_exported_csv_files/tower_of_london_history.csv', ',')
  File "export_moment_data.py", line 387, in exportToCsvTower_of_London_History
    items = query.fetch(rowsPerQuery)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2161, in fetch
    return list(self.run(limit=limit, offset=offset, **kwargs))
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2330, in next
    return self.__model_class.from_entity(self.__iterator.next())
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 1445, in from_entity
    return cls(None, _from_entity=entity, **entity_values)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 973, in __init__
    prop.__set__(self, value)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 617, in __set__
    value = self.validate(value)
  File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/ext/db/__init__.py", line 2855, in validate
    % (self.name, len(value), self.MAX_LENGTH))
BadValueError: Property move_time_stamps is 3085 bytes long; it must be 1500 or less.
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“export_moment_data.py”,第568行,在
exportToCsvTower_of_London_History(查询'moment_exported_csv_文件/tower_of_London_History.csv',',')
文件“export\u moment\u data.py”,第387行,位于伦敦历史的exportToCsvTower\u中
items=query.fetch(rowsPerQuery)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/google/appengine/ext/db/__________.py”,第2161行,在fetch中
返回列表(self.run(limit=limit,offset=offset,**kwargs))
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/google/appengine/ext/db/_________.py”,下一行2330
从实体(self.\u迭代器.next())返回self.\u model.\u class.)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/google/appengine/ext/db/__________.py”,第1445行,from_entity
返回cls(无,\u从\u实体=实体,**实体\u值)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/google/appengine/ext/db/\uuuuuuuuuu init\uuuuuuu.py”,第973行,在\uuuu init中__
属性设置(自身,值)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/google/appengine/ext/db/\uuuuuu init\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu__
value=self.validate(值)
文件“/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine default.bundle/Contents/Resources/google\u appengine/google/appengine/ext/db/___________.py”,验证中第2855行
%(self.name、len(值)、self.MAX_长度)
BadValueError:属性移动时间戳的长度为3085字节;它必须是1500或更少。

发布错误消息的完整回溯会很有帮助。根据TextProperties可以超过1500,因此我认为您可能有旧数据,其中
move\u time\u stamps
曾经是
StringProperty
,或者您的数据有些奇怪。@AaronD,我添加了完整的回溯只有当有一行的移动时间戳超过1500字节时才会发生。我创建了一个虚拟行只是为了测试它。否则,它可以正常工作。正如这里所述(根据您的回溯):异常是在
StringProperty
类中引发的,而不是
TextProperty
类中引发的。您是否有可能查询的是另一个类,而不是伦敦塔历史,其中移动时间戳仍然是一个
StringProperty
?或者您是否有使用不同类型属性定义两次的
Tower\u of_London\u History
类?