簡體   English   中英

AttributeError: 'tuple' object 沒有屬性 'get' discord/python

[英]AttributeError: 'tuple' object has no attribute 'get' discord/python

我收到此錯誤:

File "d:\python-project\import disnake.py", line 28, in get_stat_embed
    if (err_c := data.get("err", None)) is not None:
AttributeError: 'tuple' object has no attribute 'get'

並在發送嵌入后的 discord 這是一個意外錯誤。 如果問題仍然存在,請通知某人。

from cgitb import text
import requests
import disnake
from bs4 import BeautifulSoup
import datetime
import os


def _get_stats() -> dict[str: str | int] | dict[str: int]:
 nickname = 'gamer'
 url = "https://test.com/profile/"
 response = requests.get(url+nickname)
 soup = BeautifulSoup(response.text, 'lxml')
 ptss = soup.find_all('span',class_='i-pts')
 for pts in ptss:
     myptstrue = (pts.text)

 cdacs = soup.find_all('span',id='k-num')
 for cdac in cdacs:
  mykdatrue = (cdac.text)
 return(myptstrue,mykdatrue)



def get_stat_embed() -> disnake.Embed:
     data = _get_stats()

     if (err_c := data.get("err", None)) is not None:
      return disnake.Embed(title="Error", description=err_c, color=0xd31145)

     embed = disnake.Embed(title=f"test - 19 data", description="hello", color=0x280a59)
     embed.set_thumbnail(url="https://upload.wikimedia.org/wikipedia/commons/8/82/SARS-CoV-2_without_background.png")
      #embed.set_footer(text=f"id: {data['id']}")

     return embed

您的數據類型是元組。 這意味着您無法像字典一樣獲取它的值。 您應該使用索引來獲取其值。 像數據[0]等。

我認為您正在使用的庫中的一個值是返回一個元組您是否嘗試將元組轉換為列表?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM