From 38fde983286cba0b5c29ce1c840ec729effa0460 Mon Sep 17 00:00:00 2001 From: Vadzim Verhasau Date: Thu, 25 Mar 2021 21:22:35 +0300 Subject: [PATCH] Catching 502 error (#19) * Catching 502 response from server * Updated all dependencies. * Updated lxml to 4.6.3 to resolve security issues. --- .github/workflows/codestyle.yml | 2 +- .github/workflows/publish.yml | 6 ++---- codeforces_api/api_request_maker.py | 7 ++----- codeforces_api/api_requests.py | 2 ++ codeforces_api/version.py | 2 +- requirements.txt | 4 ++-- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.github/workflows/codestyle.yml b/.github/workflows/codestyle.yml index 701c288..de4120e 100644 --- a/.github/workflows/codestyle.yml +++ b/.github/workflows/codestyle.yml @@ -20,7 +20,7 @@ jobs: with: python-version: "3.9" - name: Cache pip - uses: actions/cache@v2 + uses: actions/cache@v2.1.4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 00eb41e..4338b94 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,15 +19,13 @@ jobs: matrix: python-version: [3.6, 3.7, 3.8, 3.9] steps: - - name: Print Github refs - run: echo ${{github.ref}} - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Cache pip - uses: actions/cache@v2 + uses: actions/cache@v2.1.4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} @@ -51,7 +49,7 @@ jobs: with: python-version: 3.9 - name: Cache pip - uses: actions/cache@v2 + uses: actions/cache@v2.1.4 with: path: ~/.cache/pip key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} diff --git a/codeforces_api/api_request_maker.py b/codeforces_api/api_request_maker.py index 178dae5..725e37c 100644 --- a/codeforces_api/api_request_maker.py +++ b/codeforces_api/api_request_maker.py @@ -23,8 +23,8 @@ class CodeforcesApiRequestMaker: - _api_key = "" - _secret = "" + _api_key = None + _secret = None _rand = 0 assigned_rand = False anonimus = False @@ -55,11 +55,8 @@ def generate_request(self, method_name, **fields): """ Generates request URL and data for API. """ - request_url = "https://codeforces.com/api/" + str(method_name) - if not self.anonimus: - # Renew Rand if not self.assigned_rand: self.renew_rand() diff --git a/codeforces_api/api_requests.py b/codeforces_api/api_requests.py index 33e21c9..c42f528 100644 --- a/codeforces_api/api_requests.py +++ b/codeforces_api/api_requests.py @@ -50,6 +50,8 @@ def _make_request(self, method, **payload): request = self.session.request( self.method, request_data["request_url"], data=request_data["data"] ) + if request.status_code == 502: + raise SystemError("Codeforces is unavailable now.") return self.get_response(request) def __init__(self, api_key=None, secret=None, random_number=1000000, method="POST"): diff --git a/codeforces_api/version.py b/codeforces_api/version.py index 962c851..8cb37b5 100644 --- a/codeforces_api/version.py +++ b/codeforces_api/version.py @@ -1 +1 @@ -__version__ = "2.0.7" +__version__ = "2.0.8" diff --git a/requirements.txt b/requirements.txt index a82ce15..51fc98f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,8 +14,8 @@ importlib-metadata==3.7.3 iniconfig==1.1.1 isort==5.8.0 keyring==23.0.0 -lazy-object-proxy==1.5.2 -lxml==4.6.2 +lazy-object-proxy==1.6.0 +lxml==4.6.3 mccabe==0.6.1 mypy-extensions==0.4.3 packaging==20.9