maskara
maskara

Reputation: 359

Trouble when running code on Infura - Rinkeby Testnet - HTTPError: 401 Client Error: Unauthorized for url: https://rinkeby.infura.io/

This pertains to Patrick Collins' "Solidity, Blockchain, and Smart Contract Course – Beginner to Expert Python Tutorial" on youtube.

specifically, I'm getting the following error when running my program on the Rinkeby testnet on Infura.

HTTPError: 401 Client Error: Unauthorized for url: https://rinkeby.infura.io/v3/3d6c16...

I performed the following checks as suggested by some:

Checked Private Key. It's exactly what's on my Metamask wallet.

My .env looks as follows:

export PRIVATE_KEY=0xf77f98d99d11d5d70aa230770e478aa68b4d0fbf058def08d56909373f46b4c5
export WEB3_INFURA_PROJECT_ID=c2cdf41913e344bc94720dc8244950eb

brownie-config.yaml looks like this:

dotenv: .env
wallets:
  from_key: ${PRIVATE_KEY}

I tried opening a new project(s) on Infura.io and added a new project ID to the .env but it didn't help.

The program runs fine on ganache-cli (using command: brownie run scripts/deploy.py) but not on the Rinkeby testnet (command: brownie run scripts/deploy.py --network rinkeby).

The program ran as expected yesterday as is, but not today. Internet connection is good. The full error message is as follows:

PS C:\Users\z640\demos\brownie_simple_storage> brownie run scripts/deploy.py --network rinkeby
INFO: Could not find files for the given pattern(s).
Brownie v1.16.4 - Python development framework for Ethereum

BrownieSimpleStorageProject is the active project.

Running 'scripts\deploy.py::main'...
  File "C:\Python310\lib\site-packages\brownie\_cli\run.py", line 49, in main
    return_value, frame = run(
  File "C:\Python310\lib\site-packages\brownie\project\scripts.py", line 103, in run
    return_value = f_locals[method_name](*args, **kwargs)
  File ".\scripts\deploy.py", line 66, in main
    deploy_simple_storage()
  File ".\scripts\deploy.py", line 49, in deploy_simple_storage
    simple_storage = SimpleStorage.deploy(
  File "C:\Python310\lib\site-packages\brownie\network\contract.py", line 600, in __call__
    return tx["from"].deploy(
  File "C:\Python310\lib\site-packages\brownie\network\account.py", line 508, in deploy
    receipt, exc = self._make_transaction(
  File "C:\Python310\lib\site-packages\brownie\network\account.py", line 718, in _make_transaction
    gas_price, gas_strategy, gas_iter = self._gas_price(gas_price)
  File "C:\Python310\lib\site-packages\brownie\network\account.py", line 454, in _gas_price
    return web3.eth.generate_gas_price(), None, None
  File "C:\Python310\lib\site-packages\web3\eth.py", line 846, in generate_gas_price
    return self._generate_gas_price(transaction_params)
  File "C:\Python310\lib\site-packages\web3\eth.py", line 155, in _generate_gas_price
    return self.gasPriceStrategy(self.web3, transaction_params)
  File "C:\Python310\lib\site-packages\web3\gas_strategies\rpc.py", line 20, in rpc_gas_price_strategy
    return web3.manager.request_blocking(RPC.eth_gasPrice, [])
  File "C:\Python310\lib\site-packages\web3\manager.py", line 186, in request_blocking
    response = self._make_request(method, params)
  File "C:\Python310\lib\site-packages\web3\manager.py", line 147, in _make_request
    return request_func(method, params)
  File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
    response = make_request(method, params)
  File "C:\Python310\lib\site-packages\web3\middleware\gas_price_strategy.py", line 90, in middleware       
    return make_request(method, params)
  File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
    response = make_request(method, params)
  File "C:\Python310\lib\site-packages\web3\middleware\attrdict.py", line 33, in middleware
    response = make_request(method, params)
  File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
    response = make_request(method, params)
  File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
    response = make_request(method, params)
  File "cytoolz\functoolz.pyx", line 250, in cytoolz.functoolz.curry.__call__
  File "C:\Python310\lib\site-packages\web3\middleware\formatting.py", line 76, in apply_formatters
    response = make_request(method, params)
  File "C:\Python310\lib\site-packages\web3\middleware\buffered_gas_estimate.py", line 40, in middleware    
    return make_request(method, params)
  File "C:\Python310\lib\site-packages\web3\middleware\exception_retry_request.py", line 105, in middleware 
    return make_request(method, params)
  File "C:\Python310\lib\site-packages\web3\providers\rpc.py", line 88, in make_request
    raw_response = make_post_request(
  File "C:\Python310\lib\site-packages\web3\_utils\request.py", line 49, in make_post_request
    response.raise_for_status()
  File "C:\Python310\lib\site-packages\requests\models.py", line 953, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 401 Client Error: Unauthorized for url: https://rinkeby.infura.io/v3/3d6c16...

Upvotes: 1

Views: 1054

Answers (2)

Yilmaz
Yilmaz

Reputation: 49749

This is a configuration error:

  • make sure you verified your infura account so u can use the api key.

  • make sure you used exact api key.

  • make sure you saved all the files before run the command

  • make sure metamask connected to rinkeby and has test eth

Upvotes: 0

maskara
maskara

Reputation: 359

I think I fixed the problem ( although i don't understand the mechanics of it).

I created a new Infura Project Copied the new Project ID to the appropriate location on the .env file I CLOSED THE TERMINAL and ran the brownie run scripts/deploy.py --network rinkeby command on a new terminal. This is embarrassing... it took me 2 days to figure this out :(

Upvotes: 1

Related Questions