python-dotenv icon indicating copy to clipboard operation
python-dotenv copied to clipboard

using set_key on a file over the network results in error

Open newmanjoel opened this issue 3 years ago • 0 comments

When trying to use set_key to create a .env file if one dosn't exist the first line works great but the second line always fails with this line because of the way that windows handles moving files across networks.

OSError: [WinError 17] The system cannot move the file to a different disk drive: 'C:\\Users\\[my username]\\AppData\\Local\\Temp\\tmpk0c72zk9' ->'N:\\[my username]\\Documents\\[project name]\\.env'

code that generates the error

# load the stuff that shouldn't be given out
user_config = dotenv_values(env_file_path)

if len(user_config) == 0:
    module_logger.fatal('.env file with all of the needed stuff was empty. Creating it then exiting')
    module_logger.debug(f'creating the .env file at {env_file_path.absolute()}')
    env_file_path.touch()

    module_logger.debug('setting the values inside the .env file')
    set_key(env_file_path,'username','username') # <-- this line gets written to the file
    set_key(env_file_path,'password','password') # <-- line that fails
    set_key(env_file_path,'client_id','client id (tools>options>system settings)')
    set_key(env_file_path,'client_secret','client secret (tools>options>system settings)')
    sys.exit(1)

newmanjoel avatar Jun 24 '22 17:06 newmanjoel