Skip to content

Commit

Permalink
fix: OCRSecertWith Proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
CberYellowstone committed Apr 28, 2022
1 parent 9083c54 commit 47894ac
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 20 deletions.
5 changes: 5 additions & 0 deletions Config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from yaml import CLoader as CLoader, CDumper as CDumper, load as yaml_load, dump as yaml_dump
import sys, os

NOPROXIES = {
"http": "",
"https": "",
}

isPacked = (getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'))
isInit = True

Expand Down
6 changes: 1 addition & 5 deletions MojiAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@
import itertools
import requests
import json
from Config import NOPROXIES
# from var_dump import var_dump
from urllib3 import disable_warnings

disable_warnings()

NOPROXIES = {
"http": "",
"https": "",
}

def searchWord(word: str) -> list:
try:
APIURL = "https://api.mojidict.com/parse/functions/search_v3"
Expand Down
8 changes: 4 additions & 4 deletions OCR.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from urllib3 import disable_warnings
disable_warnings()

from Config import readConfig
from Config import readConfig, NOPROXIES
configs = readConfig()

def reloadOCRConfig():
Expand Down Expand Up @@ -93,7 +93,7 @@ def checkSecretAvailable(appId: str, apiSecret: str, apiKey: str) -> bool:
request_url = assemble_ws_auth_url(url, "POST", apiKey, apiSecret)
headers = {'content-type': "application/json", 'host': 'api.xf-yun.com', 'app_id': appId}
try:
response = requests.post(request_url, data=json.dumps(_body), headers=headers,verify=False)
response = requests.post(request_url, data=json.dumps(_body), headers=headers, verify=False, proxies=NOPROXIES)
return json.loads(response.content.decode())['header']['code'] == 10009
except Exception:
return False
Expand All @@ -105,7 +105,7 @@ def getOCRResult(img) -> str:
request_url = assemble_ws_auth_url(url, "POST", configs['OCR_KEY'], configs['OCR_SECRET'])
headers = {'content-type': "application/json", 'host': 'api.xf-yun.com', 'app_id': configs['OCR_APPID']}
try:
response = requests.post(request_url, data=json.dumps(body), headers=headers,verify=False)
response = requests.post(request_url, data=json.dumps(body), headers=headers, verify=False, proxies=NOPROXIES)
tempResult = json.loads(response.content.decode())
finalResult = base64.b64decode(tempResult['payload']['result']['text']).decode()
finalResult = finalResult.replace(" ", "").replace("\n", "").replace("\t", "").strip()
Expand All @@ -116,7 +116,7 @@ def getOCRResult(img) -> str:

def getOCRSecret() -> tuple:
url = "aHR0cDovL3hmLmFrYS50b2RheS92My91c2VyX2luZm8ucGhwP29wZW5faWQ9ZmZkNjI2NDM0NDI1NDQ5MDk3YzcxZmUwMGJmYTBmNTU="
return tuple((eachDict['appId'], eachDict['apiSecret2'], eachDict['apiKey2']) for eachDict in requests.get(base64.b64decode(url)).json()['data']['all_share'] if(eachDict['apiKey2'] and eachDict['apiSecret2']))
return tuple((eachDict['appId'], eachDict['apiSecret2'], eachDict['apiKey2']) for eachDict in requests.get(base64.b64decode(url), verify=False, proxies=NOPROXIES).json()['data']['all_share'] if(eachDict['apiKey2'] and eachDict['apiSecret2']))

def getVaildOCRSecert() -> tuple:
return tuple(each for each in getOCRSecret() if(checkSecretAvailable(each[0], each[1], each[2])))
7 changes: 1 addition & 6 deletions Segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
from os import path
import importlib
disable_warnings()
from Config import isPacked

NOPROXIES = {
"http": "",
"https": "",
}
from Config import isPacked, NOPROXIES

def _kuromoji(s: str) -> list:
url = "https://www.atilika.org/kuromoji/rest/tokenizer/tokenize"
Expand Down
6 changes: 1 addition & 5 deletions TranslatorAPI.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import random

import urllib
from Config import readConfig
from Config import readConfig, NOPROXIES
import requests
import time
import uuid
Expand Down Expand Up @@ -32,10 +32,6 @@ def truncate(input):
size = len(input)
return input if size <= 20 else input[:10] + str(size) + input[size - 10: size]

NOPROXIES = {
"http": "",
"https": "",
}

CONFIG_REMIND = ",请检查是否正确设置API。"
UNDEFINED_ERROR_MESSAGE = "未知错误,请联系开发者"
Expand Down

0 comments on commit 47894ac

Please sign in to comment.