【发布时间】:2018-04-19 11:32:33
【问题描述】:
put req screenshot您好我目前正在尝试在python中解析以下post请求
-------------------------------28947758029299
Content-Disposition: form-data; name="eventData"; filename="eventData.txt"
Content-Type: application/json; charset=utf-8
{
"Rule" : "sendSpots",
"Alert" : [
{
"Event" : {
"Version" : "1",
"EventUUID" : "fe1817b9-8557-4784-b64a-617c50fe27b8",
"Type" : "Vision",
"Subtype" : "Alarm",
"SensorUUID" : "!id:9298e8e1-feb0-48e3-9c44-11ee42672ac9!",
"Origin" : "DVS-BOX-PC",
"InstanceType" : "ParkingSpaceAnalyzer",
"InstanceName" : "ParkingSpotAnalyser",
"SubName" : "P01",
"FrameTime" : "2018-04-19T09:59:41.0970000Z",
"Parameters" : [
{
"Name" : "DURATION",
"Type" : "int",
"Value" : "3669869"
},
{
"Name" : "STREAM_RESOLUTION",
"Type" : "string",
"Value" : "1280,720"
},
{
"Name" : "GENERIC_XML",
"Type" : "string",
"Value" : "<EventData><ParkingState type=\"string\">occupied</ParkingState><ParkingDurationExceeded type=\"int\">1</ParkingDurationExceeded></EventData>"
},
{
"Name" : "REGION",
"Type" : "string",
"Value" : "638,613 694,377 792,373 695,614"
}
]
}
}
]
}
-------------------------------28947758029299--
我希望将 Event 提取为字典,以便我可以访问版本值、子名称值和 SensorUUId。为了尝试提取此信息,我使用了代码
data = request.form
body = data['-------------------------------28947758029299\nContent-Disposition: form-data; name']
但是,这会以 unicode 类型返回以下内容:
"eventData"; filename="eventData.txt"
Content-Type: application/json; charset=utf-8
{
"Rule" : "sendSpots",
"Alert" : [
{
"Event" : {
"Version" : "1",
"EventUUID" : "fe1817b9-8557-4784-b64a-617c50fe27b8",
"Type" : "Vision",
"Subtype" : "Alarm",
"SensorUUID" : "!id:9298e8e1-feb0-48e3-9c44-11ee42672ac9!",
"Origin" : "DVS-BOX-PC",
"InstanceType" : "ParkingSpaceAnalyzer",
"InstanceName" : "ParkingSpotAnalyser",
"SubName" : "P01",
"FrameTime" : "2018-04-19T09:59:41.0970000Z",
"Parameters" : [
{
"Name" : "DURATION",
"Type" : "int",
"Value" : "3669869"
},
{
"Name" : "STREAM_RESOLUTION",
"Type" : "string",
"Value" : "1280,720"
},
{
"Name" : "GENERIC_XML",
"Type" : "string",
"Value" : "<EventData><ParkingState type=\"string\">occupied</ParkingState><ParkingDurationExceeded type=\"int\">1</ParkingDurationExceeded></EventData>"
},
{
"Name" : "REGION",
"Type" : "string",
"Value" : "638,613 694,377 792,373 695,614"
}
]
}
}
]
}
-------------------------------28947758029299--
我不知道该怎么走,干杯。
【问题讨论】: