Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.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
在GAE上用python创建XML树_Python_Google App Engine - Fatal编程技术网

在GAE上用python创建XML树

在GAE上用python创建XML树,python,google-app-engine,Python,Google App Engine,我有一个创建XML结构的python代码。在我笔记本电脑上的google app engine dev服务器上,一切正常,但当我将应用程序上载到GAE时,XML树在文件的根目录下追加了一个“0”,即,我得到了类似这样的结果 0<document><date>2012-01-15<entry><name>[.........] 有时,我会得到 00<document><date>2012-01-15<entry>

我有一个创建XML结构的python代码。在我笔记本电脑上的google app engine dev服务器上,一切正常,但当我将应用程序上载到GAE时,XML树在文件的根目录下追加了一个“0”,即,我得到了类似这样的结果

0<document><date>2012-01-15<entry><name>[.........]
有时,我会得到

00<document><date>2012-01-15<entry><name>[.........]
@尼克·约翰逊:添加了保存代码

tree = ET.ElementTree(xmlTree)
fileHandle = files.blobstore.create(mime_type='text/xml', _blobinfo_uploaded_filename=str(fileName))  # Create the file
with files.open(fileHandle, 'a') as f: # Open the file and write to it
    tree.write(f)
files.finalize(fileHandle) # Finalize the file.            
您需要向我们展示所有代码,而不仅仅是这一部分——以及完整的stacktrace。另外,为什么不直接使用模板生成XML呢?有几点意见:1)您不清楚使用的是哪个版本的ElementTree(例如,
ET
)。2) 您似乎有语法错误,
tree.write(f)
应该改为读取
f.write(tree)
3)您依靠写入步骤将树转换为字符串,而您应该自己执行此操作。4) 如果您的
文件名
不是字符串,为什么?如果是,您不需要使用
\u blobinfo\u uploaded\u filename=str(filename)
,只需
\u blobinfo\u uploaded\u filename=filename
即可。
self._root is not None
AssertionError
tree = ET.ElementTree(xmlTree)
fileHandle = files.blobstore.create(mime_type='text/xml', _blobinfo_uploaded_filename=str(fileName))  # Create the file
with files.open(fileHandle, 'a') as f: # Open the file and write to it
    tree.write(f)
files.finalize(fileHandle) # Finalize the file.