简体   繁体   中英

python-dotenv is not importing PRIVATE_KEY from .env file

from solcx import compile_standard
import json
from web3 import Web3
import os
from dotenv import load_dotenv



my_address = "0xDFb3e342C0A8F724bfA72e5F2773a12748977f46"
private_key = os.getenv("PRIVATE_KEY")

I am learning solidity and when I use python-dotenv to import my PRIVATE_KEY from a.env file,

export PRIVATE_KEY = 0xd6a5ea3d2c97b1dd03fd1b9c447e36791522135136665f23b0c08c6395f66d7a

it imports it as none and throws an error. this error I have given the full script that I wrote above. I hope someone can help me solve this problem

  • Make sure .env file is in the same directory.

  • Calling load_dotenv will look for .env file and sets the environment variables

    load_dotenv()

if .env file is not in the same directory you have to pass the path of.env file to load_dotenv

 load_dotenv(path_of_env)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM