[Python] Log in to the site using Python

Discussão em 'Python' iniciado por Stack, Fevereiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am successfully logging in to the website "status_code 200" But when I try to get this one from the next page, I get to the authorization page. What to do in this situation?

    import requests
    import fake_useragent
    from bs4 import BeautifulSoup

    session = requests.Session()

    link_login = "https://gta5rp.com/api/V2/users/auth/login"

    user = fake_useragent.UserAgent().random
    headers = {
    'User-Agent': user,
    'Content-Type': 'application/json'
    }

    login = '...'
    password = '...'
    data_login = {
    'login': login,
    'password': password,
    'remember': '1'
    }

    response = session.post(link_login, json=data_login, headers=headers)

    if response.status_code == 200:
    json_data = response.json()

    token = json_data.get("token")

    if token:
    headers['Authorization'] = f'Bearer {token}'

    profile_info = "https://gta5rp.com/user/report"
    profile_response = session.get(profile_info, headers=headers)

    print(profile_response.text)
    else:
    print("Ошибка: Токен не получен.")
    else:
    print(f"Ошибка авторизации: {response.status_code}, {response.text}")

    Continue reading...

Compartilhe esta Página