0

I am trying to use web3 in a Django based web application in a task which is run using celery and kafka. However while trying to use web3.eth module, I am getting the following error :

/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'

At first I was getting an error that HTTPProvider has no attribute eth, so I followed the cue from this answer, to resolve this error, however I stumbled upon this one. The strange thing is that if I run this without celery it works fine. Below is how my code snippet looks :

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

Can someone tell me, where I am going wrong with this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.