diff --git a/instagram_archiver/client.py b/instagram_archiver/client.py index 593a118..4659d8f 100644 --- a/instagram_archiver/client.py +++ b/instagram_archiver/client.py @@ -60,6 +60,10 @@ class AuthenticationError(Exception): pass +class CSRFTokenNotFound(AuthenticationError): + pass + + class InstagramClient: """The client.""" def __init__(self, @@ -118,8 +122,10 @@ def _setup_session(self, }) r = self._get_rate_limited('https://www.instagram.com', return_json=False) m = list(re.finditer(r'{"csrf_token":"([^"]+)"', r.text)) - assert len(m) == 1, m - self._session.headers.update({'x-csrftoken': m[0].group(1)}) + try: + self._session.headers.update({'x-csrftoken': m[0].group(1)}) + except IndexError as e: + raise CSRFTokenNotFound from e def _save_to_log(self, url: str) -> None: if self._no_log: diff --git a/package.json b/package.json index 0d77be2..99c5463 100644 --- a/package.json +++ b/package.json @@ -45,8 +45,8 @@ "gen-manpage": "sphinx-build -T -E -b man -d docs/_build/doctrees -D language=en docs man", "mypy": "poetry run mypy .", "qa": "yarn mypy && yarn ruff && yarn check-spelling && yarn check-formatting", - "ruff": "poetry run ruff .", - "ruff:fix": "poetry run ruff --fix .", + "ruff": "poetry run ruff check .", + "ruff:fix": "poetry run ruff check --fix .", "test": "poetry run pytest" }, "version": "0.0.1" diff --git a/pyproject.toml b/pyproject.toml index 35b4084..6e7b51c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -133,8 +133,13 @@ mock_use_standalone_module = true [tool.ruff] cache-dir = "~/.cache/ruff" -extend-ignore = ["C408", "PTH123", "Q000", "Q001", "Q003", "T201", "TD002", "TD003", "TD004"] namespace-packages = ["docs", "tests"] +line-length = 100 +target-version = "py311" +unsafe-fixes = true + +[tool.ruff.lint] +extend-ignore = ["C408", "PTH123", "Q000", "Q001", "Q003", "T201", "TD002", "TD003", "TD004"] extend-select = [ "A", "ASYNC", @@ -188,7 +193,7 @@ extend-select = [ "PLR0133", "PLR0206", "PLR0402", - "PLR1701", + "SIM101", "PLR1711", "PLR1714", "PLR1722", @@ -226,11 +231,8 @@ extend-select = [ "UP", "YTT", ] -line-length = 100 -target-version = "py311" -unsafe-fixes = true -[tool.ruff.flake8-quotes] +[tool.ruff.lint.flake8-quotes] inline-quotes = "single" multiline-quotes = "single" diff --git a/tests/conftest.py b/tests/conftest.py index 1b9859e..e3ea77b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,6 +17,6 @@ def pytest_internalerror(excinfo: pytest.ExceptionInfo[BaseException]) -> NoRetu raise excinfo.value -@pytest.fixture() +@pytest.fixture def runner() -> CliRunner: return CliRunner()