Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RaiseForStatus - новый парсер ответа #96

Open
zeegin opened this issue Nov 17, 2021 · 1 comment
Open

RaiseForStatus - новый парсер ответа #96

zeegin opened this issue Nov 17, 2021 · 1 comment

Comments

@zeegin
Copy link
Contributor

zeegin commented Nov 17, 2021

https://docs.python-requests.org/en/latest/_modules/requests/models/#Response.raise_for_status

Хочется иметь такой же метод для его промежуточного использования:

Ответ = КоннекторHTTP.Get("https://ya.ru");

КоннекторHTTP.ИсключениеПоСтатусу(Ответ);

Результат = КоннекторHTTP.КакТекст(Ответ);
@zeegin
Copy link
Contributor Author

zeegin commented Nov 17, 2021

Можно так же сразу добавить метол Ок()

    @property
    def ok(self):
        """Returns True if :attr:`status_code` is less than 400, False if not.

        This attribute checks if the status code of the response is between
        400 and 600 to see if there was a client error or a server error. If
        the status code is between 200 and 400, this will return True. This
        is **not** a check to see if the response code is ``200 OK``.
        """
        try:
            self.raise_for_status()
        except HTTPError:
            return False
        return True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant