版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wanglei_storage/article/details/80998526
最近有一个需求,就是希望部分员工在读数据的时候触发一个请求,那这个请求可以通过jenkins来触发,也可以通过脚本,或者是通过其他方式;所以写了个python socket 脚本,在用户触发请求的时候,同步数据并且返回数据同步信息
import socket
server = socket.socket()
server.bind(('0.0.0.0', 9992))
server.listen()
index_content = '''
HTTP/1.x 200 ok
Content-Type: text/html
<html>
<head>
</head>
<body>
<p>python socket response http request</p>
</body>
</html>
'''
while True:
conn, addr = server.accept()
request = conn.recv(1024).decode()
if not request: continue
method = request.split(' ')[0]
locate = request.split(' ')[1]
if method == 'GET' and locate == '/request':
print('execute sync script')
conn.sendall(index_content.encode('utf8'))
conn.close()