python 在使用websocket 或者request可能会报这个错误,这是证书认证中的错误,如果不是对安全要求高的开发,可以使用下面的方式使request与websocket正常访问
在request中修改一个参数即可正常使用:
textmod = {
"ID": "T214",
"Longitude": 123.6355038767646,
"Latitude": 42.21252408736748,
"Altitude": 555.1,
"Speed": 201,
"Direction": 30,
"Device": 7,
"Timestamp": time
}
#json串数据使用
textmod = json.dumps(textmod).encode(encoding='utf-8')
header_dict = {
"Content-Type" : "application/json",
"Authorization" : "JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZGVudGl0eSI6IjViNjk0MzRkZmQ2YzE1MmIwZDNiMmFjYSIsImlhdCI6MTU1Nzk4MzUwMCwibmJmIjoxNTU3OTgzNTAwLCJleHAiOjE1NTgwNjk5MDB9.PnlEvvTrIGE4OUd32POtrfNDeiAS53DmrTd8oM6Cb30"
}
url='https://xxxx.com:9093/dc/aircrafts/antiuav'
res = requests.post(url, data = textmod, headers = header_dict, verify=False)
在websocket中 同样改一个参数即可:
import ssl
import websockets
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
async with websockets.connect(self.ws_url, extra_headers=header, ssl=ssl_context, max_size=1000000000) as ws:
Your code to handle the connection