fix python 3.11.1 with PIL 9.4.0 conflict when create NonBrowser.

master
CHUN YU YAO 2023-01-14 13:26:42 +08:00
parent b21e5de572
commit 0151c5803e
1 changed files with 19 additions and 10 deletions

View File

@ -42,9 +42,11 @@ warnings.simplefilter('ignore',InsecureRequestWarning)
import base64 import base64
try: try:
import ddddocr import ddddocr
#PS: python 3.11.1 raise PIL conflict.
from NonBrowser import NonBrowser
except Exception as exc: except Exception as exc:
pass pass
from NonBrowser import NonBrowser
import ssl import ssl
ssl._create_default_https_context = ssl._create_unverified_context ssl._create_default_https_context = ssl._create_unverified_context
@ -1721,6 +1723,7 @@ def tixcraft_auto_ocr(driver, ocr, away_from_keyboard_enable, previous_answer, C
img_base64 = None img_base64 = None
if ocr_captcha_image_source == CONST_OCR_CAPTCH_IMAGE_SOURCE_NON_BROWSER: if ocr_captcha_image_source == CONST_OCR_CAPTCH_IMAGE_SOURCE_NON_BROWSER:
if not Captcha_Browser is None:
img_base64 = base64.b64decode(Captcha_Browser.Request_Captcha()) img_base64 = base64.b64decode(Captcha_Browser.Request_Captcha())
if ocr_captcha_image_source == CONST_OCR_CAPTCH_IMAGE_SOURCE_NON_CANVAS: if ocr_captcha_image_source == CONST_OCR_CAPTCH_IMAGE_SOURCE_NON_CANVAS:
image_id = 'yw0' image_id = 'yw0'
@ -1776,6 +1779,7 @@ def tixcraft_auto_ocr(driver, ocr, away_from_keyboard_enable, previous_answer, C
time.sleep(0.3) time.sleep(0.3)
else: else:
# Non_Browser solution. # Non_Browser solution.
if not Captcha_Browser is None:
new_captcha_url = Captcha_Browser.Request_Refresh_Captcha() #取得新的CAPTCHA new_captcha_url = Captcha_Browser.Request_Refresh_Captcha() #取得新的CAPTCHA
if new_captcha_url != "": if new_captcha_url != "":
tixcraft_change_captcha(driver, new_captcha_url) #更改CAPTCHA圖 tixcraft_change_captcha(driver, new_captcha_url) #更改CAPTCHA圖
@ -5017,11 +5021,15 @@ def tixcraft_main(driver, url, config_dict, is_verifyCode_editing, ocr, Captcha_
if each_url == url: if each_url == url:
tixcraft_home(driver) tixcraft_home(driver)
if config_dict["ocr_captcha"]["enable"]:
domain_name = url.split('/')[2] domain_name = url.split('/')[2]
#PS: need set cookies once, if user change domain. #PS: need set cookies once, if user change domain.
if not Captcha_Browser is None:
Captcha_Browser.Set_cookies(driver.get_cookies()) Captcha_Browser.Set_cookies(driver.get_cookies())
Captcha_Browser.Set_Domain(domain_name) Captcha_Browser.Set_Domain(domain_name)
break
if "/activity/detail/" in url: if "/activity/detail/" in url:
is_redirected = tixcraft_redirect(driver, url) is_redirected = tixcraft_redirect(driver, url)
@ -5260,12 +5268,13 @@ def main():
DISCONNECTED_MSG = 'Unable to evaluate script: no such window: target window already closed' DISCONNECTED_MSG = 'Unable to evaluate script: no such window: target window already closed'
ocr = None ocr = None
Captcha_Browser = None
try: try:
if config_dict["ocr_captcha"]["enable"]: if config_dict["ocr_captcha"]["enable"]:
ocr = ddddocr.DdddOcr(show_ad=False, beta=True) ocr = ddddocr.DdddOcr(show_ad=False, beta=True)
Captcha_Browser = NonBrowser()
except Exception as exc: except Exception as exc:
pass pass
Captcha_Browser = NonBrowser()
while True: while True:
time.sleep(0.1) time.sleep(0.1)