From f5fc9d60c44c4e210cd14534cf2d9bffe38e14ff Mon Sep 17 00:00:00 2001 From: Haruto Date: Fri, 13 Dec 2024 18:11:43 +0900 Subject: [PATCH] fix: problem with validation error if login expired (#17) --- .github/workflows/lint_python.yaml | 2 +- .github/workflows/publish_pypi.yml | 8 +++++++- line_works/client.py | 16 ++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/.github/workflows/lint_python.yaml b/.github/workflows/lint_python.yaml index c8c6c9c..f72845a 100644 --- a/.github/workflows/lint_python.yaml +++ b/.github/workflows/lint_python.yaml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.10", "3.11", "3.12"] + python-version: ["3.10", "3.11", "3.12", "3.13"] steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 83b3b84..d9889ae 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -8,6 +8,12 @@ on: branches: - develop pull_request: + paths: + - "**.py" + - pyproject.toml + - requirements-dev.txt + - requirements.txt + - setup.cfg jobs: setup: @@ -61,7 +67,7 @@ jobs: password: ${{ secrets.PYPI_TOKEN }} test-pypi: - if: ${{ github.event_name == 'pull_request' }} + if: ${{ github.event_name == 'pull_request' && github.actor != 'dependabot[bot]' }} needs: setup runs-on: ubuntu-latest environment: diff --git a/line_works/client.py b/line_works/client.py index da21b31..b4bde25 100644 --- a/line_works/client.py +++ b/line_works/client.py @@ -2,10 +2,10 @@ from os import makedirs from os.path import exists from os.path import join as path_join -from typing import Any, Optional +from typing import Any -from pydantic import BaseModel, Field -from requests import HTTPError, JSONDecodeError, Response, Session +from pydantic import BaseModel, Field, ValidationError +from requests import HTTPError, JSONDecodeError, Session from line_works import config from line_works.decorator import save_cookie @@ -46,19 +46,19 @@ def model_post_init(self, __context: Any) -> None: makedirs(self.session_dir, exist_ok=True) self.session.headers.update(config.HEADERS) - r: Optional[Response] = None - if exists(self.cookie_path): # login with cookie with open(self.cookie_path) as j: c = json.load(j) self.session.cookies.update(c) - r = self.session.get(TalkURL.HOST, allow_redirects=False) - if not r or r.status_code != 200: + try: + my_info = self.get_my_info() + except ValidationError as _: + self.session.cookies.clear() self.login_with_id() + my_info = self.get_my_info() - my_info = self.get_my_info() self.tenant_id = my_info.tenant_id self.domain_id = my_info.domain_id self.contact_no = my_info.contact_no