Я пытаюсь использовать web3 в веб-приложении на основе Django в задаче, которая выполняется с использованием celery и kafka.Однако, пытаясь использовать модуль web3.eth, я получаю следующую ошибку:
/blockchain_transaction_service.py", line 43, in create_signed_transaction
nonce = w3.eth.getTransactionCount(from_address)
File "/home/paras/.local/lib/python3.6/site-packages/web3/eth.py", line 234, in getTransactionCount
return self.web3.manager.request_blocking(
AttributeError: 'HTTPProvider' object has no attribute 'manager'
Сначала я получал сообщение об ошибке, что у HTTPProvider нет атрибута eth, поэтому я следовал подсказке из этого ответ , чтобы устранить эту ошибку, однако я наткнулся на эту.Странно то, что если я запускаю это без сельдерея, это работает нормально.Вот как выглядит мой фрагмент кода:
from web3 import HTTPProvider, Web3, exceptions
from web3.eth import Eth
from .constants import *
from .enums import *
from .models import *
from .SendOTP import send_gaspod_alert_mail
import logging
import ast
import os
import requests
import json
logger = logging.getLogger(__name__)
#Initialize web3
w3 = Web3(HTTPProvider(INFURA_MAIN_NET_ETH_URL))
# Global for exception message in Ethereum transactions
OUT_OF_GAS_ERROR_CODE = -3200
OUT_OF_GAS_ERROR_CODE_ETH = -32000
OUT_OF_GAS_MESSAGE = "insufficient funds for gas * price + value"
def create_signed_transaction(to_address,from_address,amount,private_key,gas) :
data = {}
try :
if to_address is None or from_address is None or gas is None or private_key is None or amount is None:
raise Exception("Invalid params")
if amount <=0 :
raise Exception("Invalid parameter amount cannot be less or equals to 0")
to_address = Web3.toChecksumAddress(to_address)
from_address = Web3.toChecksumAddress(from_address)
w3 = Web3.HTTPProvider(RPOSTON_INFURA_TEST_URL)
Eth.attach(w3,"eth")
print(w3)
print(type(w3))
nonce = w3.eth.getTransactionCount(from_address)
gas_price = w3.eth.gasPrice
value= Web3.toWei(amount,"ether")
signed_txn = w3.eth.account.signTransaction(dict
(
nonce=nonce,
gasPrice = gas_price,
gas = gas,
to=to_address,
value=value
),
private_key)
data["signed_txn"] = signed_txn
return data
except Exception as e :
import traceback
print(traceback.format_exc())
data = {}
error = "Unable to create signed transaction " + str(e)
data["signed_txn"] = None
data["error"] = error
return data
Может кто-нибудь сказать мне, где я ошибаюсь?