jeudi 4 novembre 2021

Signing into website through python: TypeError: 'NoneType' object is not subscriptable

I'm trying to set a program that will allow a user to enter an id and sign into a specific website. The token (used to sign in) is from discord but it has nothing to do with the api (as I already have a token and this program runs outside of discord). The website url is discord.id. I know nothing about this so if it is a simple mistake please forgive me and answer or send me the correct resources to fix the mistake. The code:

from requests import Session
from bs4 import BeautifulSoup as bs


def target_id_enter():
    while True:
        try:
            target_id = int(input("Enter target id: "))
            print(target_id)
            discord_id_website()
        except ValueError:
            print("Target id needs to be an integer")


def discord_id_website():
    with Session() as s:
        site = s.get("https://discord.id/")
        bs_content = bs(site.content, "html.parser")
        token = bs_content.find("input", {"name": "csrf_token"})["value"]
        login_data = {"enter_token": "530791679704301580", "csrf_token": token}
        s.post("https://discord.id/", login_data)
        home_page = s.get("https://discord.id/")
        print(home_page.content)


target_id_enter()

The error:

File "D:\Atom Projects\DCF\main.py", line 19, in discord_id_website
    token = bs_content.find("input", {"name": "csrf_token"})["value"]
TypeError: 'NoneType' object is not subscriptable

I have looked at many sources to aid me and have found nothing. The only 2 stack overflow questions that seemed relevant (from their title) don't help at all. Python: TypeError: 'NoneType' object is not subscriptable and Python Math - TypeError: 'NoneType' object is not subscriptable. Thank you for any help.

Note: the website also contains a capcha (only a button click) and I also need to get around that. The token that is entered doesn't work yet as I want to put a varible in my disctionary.




Aucun commentaire:

Enregistrer un commentaire