TypeError: 'type' object is not subscriptable web3.py

TypeError: 'type' object is not subscriptable web3.py

嘿,我收到 TypeError: 'type' object is not subscriptable when trying to print SimpleStorage.I am using env, my python version is 3.10.0 n the library is web3.py idk 如果这足够了这是我在 stakeoverflow 上的第一个问题

from solcx import compile_standard, install_solc
import json
from web3 import Web3

with open("./SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()
print("Installing...")
install_solc("0.6.0")

compiled_sol = compile_standard(
    {
        "language": "Solidity",
        "sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
        "settings": {
            "outputSelection": {
                "*": {
                    "*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]
                }
            }
        },
    },
    solc_version="0.6.0",
)


with open("compiled_code.json", "w") as file:
    json.dump(compiled_sol, file)

# get the bytecode

bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
    "bytecode"
]["object"]

# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]

w3 = Web3(Web3.HTTPProvider["http://127.0.0.1:7545"])
chain_id = 5777
my_address = "0x4bAB8D6D8b8959B1B7DaBd40B39eDFA8C07144C8"
private_key = "0xa5311c1f5d113053b3cfd4ef7ad1375a4030825d2f6bdf4131f28ae2331e1b6c"


# Create the contract in python

SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
print(SimpleStorage)

使用 () 而不是 []。使用 [] 将其视为可下标的 object/container,这意味着它们包含其他对象。比如字符串、列表、元组和字典。

w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))

当您尝试使用数据类型为“type”的索引访问对象时,会引发“TypeError: ‘type’ object is not subscriptable”错误。要解决此错误,请确保您仅尝试使用索引访问可迭代对象,例如元组和字符串。

w3中存储的数据类型是什么?