Help With Brownie and Infura Environment Variables (Will send a $tip for the help)

Hello, I’m a novice to coding in general and I’m stuck with a problem while trying to run a script using Brownie in Studio Visual Code. I think my problem is with the environment variables in brownie(I’m probably doing something wrong in the brownie-config.yaml file) while trying to use the Kovan test network. I’ve used Infura to create a Project ID, and I have metamask for a private key. When I run “brownie run scripts/ --network kovan” I receive this error “raise ValueError(f"Unable to expand environment variable in host setting: ‘{uri}’”)
ValueError: Unable to expand environment variable in host setting: ‘$WEB3_INFURA_PROJECT_ID’’ Do you have any suggestions? Thank you. This may be a simple solution for someone, and I’ll send a tip to someone that’s willing to help guide me through a few steps. Thanks again.

1 Like

Hey @Brian_Lee_Victory, and welcome to the Infura community! After doing some digging and carefully looking at your error messages, I don’t think this is a Brownie issue as much as a Python issue.

You may want to look into os.path.expandvars(path) on this page. This will alow you to expand the environment variables at whatever path you put into it, which would be the Kovan URL you have mentioned.

Let me know if that works! If not, we’ll keep digging! :slight_smile:

1 Like

Hi @Leiya_Kenney, thank you so much for the reply and info. I’ve been reading over that article as I try to gain an understanding of environment variables since I’m new to coding in general. At the moment I"m receiving this Attribute error from running a script in Brownie, so I’ll just have to keep digging:

$ brownie run scripts/ --network kovan
INFO: Could not find files for the given pattern(s).
Brownie v1.14.3 - Python development framework for Ethereum

NewFolderProject is the active project.
  File "c:\users\brian, line line, in in
    return_value, frame = run(
  File "c:\users\brian, line line, in in
    raise AttributeError(f"Module '{name}' has no method '{method_name}'")
AttributeError: Module 'Users.Brian Lee.Python39.brownie.New folder.scripts.deploy' has no method 'main```

So that INFO error at the top is telling you that python.exe is not in the path that you’re trying to run - I’d check into fixing that first! When in doubt, follow the error messages :slight_smile:

1 Like

Hi Brian,
Just came across this. It looks like your first issue can be solved with this:

And your 2nd issue can be solved by adding a function named main in your script.

Hope it helps.


I am also getting similar issue. Are you able to resolve it? If yes then can you post the solution that you have found.

1 Like

Hi @Bhushan_P, and welcome to the Infura community! What error message are you seeing?

Hi @Brian_Lee_Victory,

Did you manage to solve the first issue?

I’m getting the same error message.

I created an .env file in my folder and added my private key in there and also the infura project id.

Also I tried to add the private key and the infura project id to a bash file when a terminal opens.

It seems like a tutorial to use the.env file, to set the infura project id and to set the private key hidden and to get these from inside Brownie would help.

This is essential to deploy a script on the Kovan network.

Has anyone figured this part out?

I have looked at most links here with the solution. But until now I have not been able to deploy on kovan.

I’m following your youtube workshop on Brownie. The 1 hour one and also the 16 hours one! Lol.

Keep up the great work!!!

But this little environment thing - I’m using a Mac - is in my way to achieve your greatness with Brownie!!!

1 Like

I had the same issue and it turned out the environment variable WEB3_INFURA_PROJECT_ID had a space at the end. Removing it fixed the problem.
Hope that helps.

Hi @Runy_Calmera

Could you please let us know if you managed to resolve the issue you’re encountering?

Hey, I am getting the same issue when trying to run brownie, i get stuck on launching ganache-cli.cmd. My dotenv file has my ID and all my dependencies i believe are installed correctly

Hi @Anthony_Tilotta, thank you for writing in, and welcome to the Infura community!

It looks like you have a similar issue that was described earlier in regards to ‘INFO’ warning. Would you be able to look into python.exe? As Leiya mentioned earlier, python.exe is not in the path that you’re trying to run.

Some additional resources you can find here.

hey thanks for the reply, python.exe is installed but for some reason brownie can’t find it or cant find itself…lol when i type brownie --version i get the same INFO error but then it lists all the brownie dependencies so im confused. any other tips? also, what is the command to uninstalled brownie and just start all over? im new to coding in general so im sorry if some of my logic on this issue is incorrect. im basically trying to utilize the arbitrage bot code that @PatrickAlphaC so generously put out and im stuck at deploying the scripts

it seems that the INFO warning is nothing but a warning so i think im good… however im following along with @PatrickAlphaC flashloan video tutorial and im at the part where he is getting WETH - but running this command: brownie run scripts/ --networks kovan

I get this unauthorized for url HTTPError…

Hi Anthony,
I’m having a similar issue and the repo from StackExchange doesn’t help me at all. Have you found a solution to your problem?

I’ve read through all the comments and I feel like I am doing everything correctly. I followed along with Patrick and I also cloned his project to see if I could figure out whats wrong. Can anyone see what the problem might be?

I have a similar issue! The API Key gets replaced but there is an additional %0D at the end which renders it useless! %0D
why is this? I am using brownie as well.

For anyone with this same issue kindly check your working directory first…