brownie: ValueError: Unable to expand environment variable in host setting

Environment information

  • eth-brownie>=1.10.0,<2.0.0
  • ganache-cli Version: 6.12.2
  • solc Version: 0.6.6
  • Python Version: 3.8.5
  • OS: linux (ubuntu 20.04)

What was wrong?

Please include information like:

  • what command you ran brownie run scripts/simple_collectible/deploy_simple.py --network rinkeby

  • the code that caused the failure (see this link for help with formatting code)

  • full output of the error you received

NftMixProject is the active project.
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/run.py", line 43, in main
    network.connect(CONFIG.argv["network"])
  File "brownie/network/main.py", line 40, in connect
    web3.connect(host, active.get("timeout", 30))
  File "brownie/network/web3.py", line 51, in connect
    uri = _expand_environment_vars(uri)
  File "brownie/network/web3.py", line 171, in _expand_environment_vars
    raise ValueError(f"Unable to expand environment variable in host setting: '{uri}'")
ValueError: Unable to expand environment variable in host setting: 'https://rinkeby.infura.io/v3/$WEB3_INFURA_PROJECT_ID'

How can it be fixed?

Fill this in if you know how the bug could be fixed.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 53 (14 by maintainers)

Most upvoted comments

So I ran into this issue while I was doing test_lottery_unit.py of @PatrickAlphaC 's tutorial.

This might help you guys. Add this to the script

from dotenv import load_dotenv

load_dotenv()

I also ran into this issue running brownie test -k test_get_entrance_fee --network rinkeby

solved by adding dotenv: .env to brownie-config.yaml

Looks like this is from the new .env file improvement. https://eth-brownie.readthedocs.io/en/stable/config.html?highlight=.env#dotenv

It’s not pulling in env variables at the project level, so I can’t use the .env variables in my project, only in my yaml. Is this the intended effect? I’m running into the same issue.

You can run source .env before you run the brownie run scripts/get_weth.py --network kovan

Great call. I can add that in!

On Apr 5, 2021, at 16:36, Patrick Collins @.***> wrote:

For clarity, the original improvement that went in was good 😃

This would be a new one, to allow the .env vars to work across scripts too. And ideally you could set your WEB3_INFURA_PROJECT_ID in the .env file too

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

Just encountered this error myself. For me, running VS code as admin solved it.

Ran in the same issue and adding dotenv: .env to brownie-config.yaml will solve it. Also remember to put .env in the main folder

in brownie-config.yaml add this dotenv : .env

Okay I’ve just realised what my problem is - the brownie-config.yaml file has to be at the root of the project e.g

  • my-sample-project

    • brownie-config.yaml
    • .env

@redcloud86 maybe try that?

This solved it for me too…oops!

For anyone still facing the issue after trying everything suggested in this thread: To me it happened in Lesson 10: Defi & Aave, it might sound silly, but when following close to the tutorial around 09:01:00, the script is run before you ever compiled the code. So if you have the same issue as me, try running

brownie compile 

before running the script.

Okay I’ve just realised what my problem is - the brownie-config.yaml file has to be at the root of the project e.g

  • my-sample-project

    • brownie-config.yaml
    • .env

@redcloud86 maybe try that?

thanks for the suggestion @tobiade I managed to figure it out

Okay I’ve just realised what my problem is - the brownie-config.yaml file has to be at the root of the project e.g

  • my-sample-project
    • brownie-config.yaml
    • .env

@redcloud86 maybe try that?

Yes - do you want me to close it since I opened it?

Sent from my iPhone

On Jul 19, 2021, at 16:13, Patrick Collins @.***> wrote:

Can we close this? It appears to have been fixed

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.