1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| import requests import random, time import hashlib
random_str = ''.join(random.choices('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', k=16)) timestamp = str(int(time.time())) app_id = "e59RqtUBzXil5jvF4I1b4cfq" app_secret = "xxxxx"
url = "https://server.simpletex.cn/api/latex_ocr" header = {"random-str": random_str, "timestamp": timestamp, "app-id": app_id} data = {'file': open('test.png', 'rb')}
sign_str = f'app-id={app_id}&random-str={random_str}×tamp={timestamp}&secret={app_secret}'
signature = hashlib.md5(sign_str.encode()).hexdigest() header["sign"] = signature x = requests.post(url, files=data, headers=header)
print(x.text)
|