Warum geht dieser Discord Bot nicht?

Fehlermeldung:

Traceback (most recent call last):
  File "C:\Users\lennox\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 261, in static_login
    data = await self.request(Route('GET', '/users/@me'))
  File "C:\Users\lennox\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 225, in request raise HTTPException(r, data)
    discord.errors.HTTPException: 401 Unauthorized (error code: 0): 401: Unauthorized
    The above exception was the direct cause of the following exception:
    Traceback (most recent call last):
      File "C:\Users\lennox\Downloads\QuicSilver Discord bot.py", line 11, in <module>
        client.run('fqbm4Q4mGGgAA70WQ3qu9gvGYHhbrP0i')
      File "C:\Users\lennox\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 640, in run
        return future.result()
      File "C:\Users\lennox\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 621, in runner
        await self.start(*args, **kwargs)
      File "C:\Users\lennox\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 584, in start
        await self.login(*args, bot=bot)
      File "C:\Users\lennox\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 442, in login
        await self.http.static_login(token.strip(), bot=bot)
      File "C:\Users\lennox\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\http.py", line 265, in static_login
        raise LoginFailure('Improper token has been passed.') from exc
discord.errors.LoginFailure: Improper token has been passed.

Skript:

import discord

class MyClient(discord.Client):
  async def on_ready(self):
    print("Online!")

  async def on_message(self, message):
    print(message.author + ":" + message.content)

client = MyClient()
client.run('fqbm4Q4mGGgAA70WQ3qu9gvGYHhbrP0i')

PS.: Fake-Token

PC, Computer, Python, py, python-3, discord, Discord Server, Discord Bot
1 Antwort
Python wie löse 'NoneType' object is not subscriptable?

Hallo!

Ich schreibe ein kleines Pythonprogramm, das als Web Crawler fungieren soll.Leider erhalte ich in Zeile 36 ein Fehler:

  brand = make_rating_sp[0].img["title"].title()
TypeError: 'NoneType' object is not subscriptable

Leider, finde ich keine Lösung. Wie könnte ich diesen Fehler lösen? Danke im Voraus!

make_rating_sp[0].img is None.

from bs4 import BeautifulSoup as soup  # HTML data structure
from urllib.request import urlopen as uReq  # Web client

# URl to web scrap from.
# in this example we web scrap graphics cards from Newegg.com
page_url = "http://www.newegg.com/Product/ProductList.aspx?Submit=ENE&N=-1&IsNodeId=1&Description=GTX&bop=And&Page=1&PageSize=36&order=BESTMATCH"

# opens the connection and downloads html page from url
uClient = uReq(page_url)

# parses html into a soup data structure to traverse html
# as if it were a json data type.
page_soup = soup(uClient.read(), "html.parser")
uClient.close()

# finds each product from the store page
containers = page_soup.findAll("div", {"class": "item-container"})

# name the output file to write to local disk
out_filename = "graphics_cards.csv"
# header of csv file to be written
headers = "brand,product_name,shipping \n"

# opens file, and writes headers
f = open(out_filename, "w")
f.write(headers)

# loops over each product and grabs attributes about
# each product
for container in containers:
    # Finds all link tags "a" from within the first div.
    make_rating_sp = container.div.select("a")

    # Grabs the title from the image title attribute
    # Then does proper casing using .title()
    brand = make_rating_sp[0].img["title"].title()

    # Grabs the text within the second "(a)" tag from within
    # the list of queries.
    product_name = container.div.select("a")[2].text

    # Grabs the product shipping information by searching
    # all lists with the class "price-ship".
    # Then cleans the text of white space with strip()
    # Cleans the strip of "Shipping $" if it exists to just get number
    shipping = container.findAll("li", {"class": "price-ship"})[0].text.strip().replace("$", "").replace(" Shipping", "")

    # prints the dataset to console
    print("brand: " + brand + "\n")
    print("product_name: " + product_name + "\n")
    print("shipping: " + shipping + "\n")

    # writes the dataset to file
    f.write(brand + ", " + product_name.replace(",", "|") + ", " + shipping + "\n")

f.close()  # Close the file
Programmieren, Programmierung, Informatik, Python, python-3
1 Antwort

Meistgelesene Fragen zum Thema Python-3