1

Использую python 3.8 и requests 2.7.0 Отправляя пост запрос логина на сайт https://forum.exbo.su/login я получаю в ответ не страницу, с ошибкой логина(должна быть ошибка, тк пароль и ник неверные), а страницу с текстом "You have been inactive for too long. Go back and try again." В чем проблема? Код ниже

import requests
login = 'login'
password = 'password'
api_sender = requests.session()
source = api_sender.post("https://forum.exbo.su/login", data={"identification": login,
                                                         "password": password,
                                                         "remember": False}).text
print(source)

В ответ получаю:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    
    <title>EXBO Forum</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">

    <style>
      * {
       box-sizing: border-box;
      }
      body {
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
        font-size: 18px;
        text-align: center;
        line-height: 1.5;
        color: #333;
      }
      input,
      button,
      select,
      textarea {
        font-family: inherit;
        font-size: inherit;
        line-height: inherit;
      }
      a {
        cursor: pointer;
        color: #00ade4;
        text-decoration: none;
        font-weight: bold;
      }
      a:hover {
        text-decoration: underline;
      }
      .container {
        margin: 100px auto;
        max-width: 450px;
        padding: 0 15px;
      }
      .button {
        display: inline-block;
        padding: 15px 25px;
        background: #00ade4;
        color: #fff;
        text-decoration: none;
        text-align: center;
        vertical-align: middle;
        border-radius: 4px;
        cursor: pointer;
        white-space: nowrap;
        font-weight: bold;
        border: 0;
      }
      .button:hover {
        text-decoration: none;
      }
      .button:active,
      .button.active {
        box-shadow: inset 0 3px 5px rgba(0, 0, 0, .125);
      }
      .form {
        max-width: 300px;
        margin: 0 auto;
      }
      .form .button {
        display: block;
        width: 100%;
      }
      .form-control {
        display: block;
        width: 100%;
        text-align: center;
        padding: 15px 20px;
        background-color: #fff;
        border: 2px solid #eee;
        border-radius: 4px;
        transition: border-color .15s;
      }
      .form-control:focus,
      .form-control.focus {
         border-color: #00ade4;
         outline: none;
      }
      .errors {
        color: #d83e3e;
      }
      .errors ul {
        list-style-type: none;
        margin: 0;
        padding: 0;
      }
    </style>
  </head>

  <body>
    <div class="container">
        <p>
    You have been inactive for too long.
  </p>
  <p>
    <a href="javascript:history.back()">
      Go back, to try again
    </a>
  </p>
    </div>
  </body>
</html>

В чем проблема?

1 ответ 1

0

Это происходит из-за того, что сайт пытается защититься от CSRF атаки (Double Submit Cookie). Т.е. в вашем случае нужно дополнительно отправлять headers={'x-csrf-token':..., 'cookie':...}

2
  • Ваш ответ помог решить проблему, но как получать новый token, когда он обновляется. Т.е после входа в аккаунт через запрос, токен обновляется и попытки повторного входа дают ту же ошибку, что и была в начале. Как получить ответ от сайта, чтоб в нем содержался новый токен? 31 дек 2019 в 12:01
  • @Евгений сделать любой запрос, например, на главную страницу и достать из заголовков нужную инфу 31 дек 2019 в 12:18

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.