【发布时间】:2019-08-06 11:26:56
【问题描述】:
我正在将数据接收到 REST API 中,并且我想将其作为 XML 代码插入到数据库中。当我后来从数据库中读取记录时,我希望 XML 代码格式正确。
data=str(request.data)
cur=mydb.cursor()
currentDT = datetime.datetime.now()
val=data.replace("'","''")
cur.execute("insert into MyXMLApi(dateofInsertion,xmlData) values('%s','%s')"%(str(currentDT),val))
mydb.commit()
这是我期望在数据库中看到的:
"<note>
Don't forget me this weekend!
</note>"
然而,这是我实际得到的:
'b"<note>
Don''t forget me this weekend!
</note>"'
所以我这里有三个问题。
- 我必须处理 XML 代码中的单引号。
- 它应该存储为正确的 XML 代码。
- 当我从数据库中读取时,我无法获得正确的代码。
【问题讨论】:
标签: mysql python-3.x flask