Skip to content

Commit

Permalink
检测本地 OCR 是否运行
Browse files Browse the repository at this point in the history
  • Loading branch information
moeshin committed Mar 31, 2023
1 parent ecc9e25 commit b70f8af
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions utils/port.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import socket
import requests


def detectPort(port=6666) :

s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
def detectPort(port=6666):
try:
s.connect(("127.0.0.1", int(port)))
s.shutdown(2)
sign = True
except Exception :
sign = False
s.close()

return sign
return requests.head("http://127.0.0.1:%d/ocr/api" % port, timeout=2).headers.get("Dango-OCR") == "OK"
except Exception:
return False

0 comments on commit b70f8af

Please sign in to comment.