When doing vision, we need to get RTSP value by requesting Hikon background process 1. Obtain the camera code from the database (the camera code is provided by Hikon platform) 2. Send POST request for the camera code (In this part of the unit, JAVA uses Hikon’s package to transfer the request) 3. Obtain the RTSP (camera encoding is correct + request interface is correct) by regularize the returned data. Example returned data contains RTSP (correct), data:None, and camera encoding is not found respectively

{'code': 200, 'data': '{" code ":" 0 ", "MSG" : "success", "data" : {" url ":" RTSP: / / 202.110.241.70:556 / openUrl/z3dTw08 "}}'} {' code: 200, 'data':'None'} {'code': 200, 'data': '{"code":"0x01b01301","msg":"Camera not found. cameraIndexCode not found, cameraIndexCode=24f5fd1866dd4367ac3d3146bf96629b","data":null}'}Copy the code

‘data’:’None’ :’ data’:’None’ :’ data’:’None’ :’ data’:’None’

RestInfo = self.UrlHighAltitudeIndexCode + CamId RestData = requests.post(RestInfo) RestDataDict = RestData.json() Datas  = RestDataDict['data'] print(RestDataDict) RTSP = None if Datas is not None: Data_RestDataDict = ((eval(RestDataDict['data']))['data']) RTSP = Data_RestDataDict['url'] return RTSPCopy the code

CameraIndexCode: Camera not found cameraIndexCode: Camera not found cameraIndexCode: Camera not found cameraIndexCode: Camera not found cameraIndexCode: Camera not found cameraIndexCode: Camera not found cameraIndexCode: Camera not found

RestInfo = self.UrlHighAltitudeIndexCode + CamId RestData = requests.post(RestInfo) RestDataDict = RestData.json() Datas  = RestDataDict['data'] print(RestDataDict) RTSP = None if Datas is not None: EoorCode = "0x01b01301" RightCode = EoorCode in Datas print(CamId, RightCode) if RightCode is False: Data_RestDataDict = ((eval(RestDataDict['data']))['data']) RTSP = Data_RestDataDict['url'] return RTSPCopy the code

I feel like I’m writing poop, which is disgusting, but at least it works. Feel for a long time can’t write tuo excrement come out, be tuo excrement, that also have to be lazy. As of the current version, the RTSP is filtered by whether it contains RTSP or not

data = {'cameraIndexCode': CamId}
RestData = requests.post(self.UrlConstructionIndexCode, data=data)
RestDataDict = RestData.json()
# print(RestDataDict)
RTSP = None
RightInfo = "rtsp" in str(RestDataDict)
if RightInfo is True:
    Data_RestDataDict = ((eval(RestDataDict['data']))['data'])
    RTSP = Data_RestDataDict['url']
return RTSP
Copy the code

I don’t know if I can optimize it any more