0
0

【python】paddleocrのSSLエラーとプロキシ設定

Posted at

今回のエラー


def tst(img_path):
    ocr = PaddleOCR(use_angle_cls=True, lang='japan')
    result = ocr.ocr(img_path, cls=True)
    for idx in range(len(result)):
        res = result[idx]
        for line in res:
            print(line)

if __name__ == "__main__":

  img_path = 'tst.pdf'
  tst(img_path)

を実行で

requests.exceptions.SSLError: HTTPSConnectionPool(host='paddleocr.bj.bcebos.com', port=443): Max retries exceeded with url: /PP-OCRv3/multilingual/Multilingual_PP-OCRv3_det_infer.tar (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1006)')))

と出る。

PaddleOCRを使うにはモデルが必要で、言語ごとのモデルがなければサーバから落とすという仕様らしいです。
そこにプロキシガードが来てこうなった、と。
要するによくあるプロキシ問題です。

解決方法

https://github.com/PaddlePaddle/PaddleOCR/discussions/7024
issueで参考になりそうなやつ、すなわちrequest処理を直々に書き換える処理を採用。

下記、原文ママです。

Find site-packages\paddleocr\ppocr\utils\network.py, and modify the following code

def download_with_progressbar(url, save_path):
    logger = get_logger()
    response = requests.get(url, stream=True,proxies={'https':'http://127.0.0.1:4378'})

site-packages\paddleocr\ppocr\utils\network.pyにあるdownload_with_progressbarを書き換えるだけ!
プロキシサーバなんてわかんねーよな人は「verify=False」とか書いとけばいいと思います。

これで動かせば無事モデルを落としてくれます。
モデルなければ落とすという処理なので、一度落としたらあとは元に戻しても問題なさそうです。

ちなみにモデルは下記に保存されました。これは圧縮ファイルですが。

C:\Users\wagahaiCAT/.paddleocr/whl\det\ml\Multilingual_PP-OCRv3_det_infer\Multilingual_PP-OCRv3_det_infer.tar
C:\Users\wagahaiCAT/.paddleocr/whl\rec\japan\japan_PP-OCRv4_rec_infer\japan_PP-OCRv4_rec_infer.tar
C:\Users\wagahaiCAT/.paddleocr/whl\cls\ch_ppocr_mobile_v2.0_cls_infer\ch_ppocr_mobile_v2.0_cls_infer.tar

windows環境以外はパス違うかもなのでご了承ください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0