websocket接口如何处理
在接口自动化中,HTTPS类型的接口使用request库可以解决,webservier接口可使用suds-py3第三方库【webserver接口基本不用】;那么websocket接口怎样请求?
python中也同样提供了许多第三方库,比如接下来要说的websocket-client
websockt-client创建socket客户端有两种方式:create_connection、websocketapp
create_connection
使用create_connection创建socket客户端代码如下:
from websocket import create_connection
class webSocket_conn:
"""
1、使用websocket中的create_connection
"""
def __init__(self, url: str):
"""
初始化,建立连接
:param url:
"""
try:
logger.info(f"初始化create_connection连接url:{
url}")
self.ws = create_connection(url)
if self.ws.getstatus() == 101:
logger.info(f"初始化连接成功,连接状态为:{
self.ws.getstatus()}")
except:
logger.warning(f"初始化websocket——conn连接失败!!!当前连接状态为:{
self.ws.getstatu

1万+

被折叠的 条评论
为什么被折叠?



