4

To give a little bit of background, I have to set environment variables http_proxy and https_proxy for my school's proxy, and the password changes based on what day it is. So as a hypothetical example, on Monday the password would be cat, and on Tuesday it would be dog. The reason way I want to create a Python script to automatically change the password as the day changes is because I have scripts that I run over night, and I do not want to have to go to my computer at 12:01AM and change yesterday's password to today's password.

I have already written an algorithm for changing my password every day, so that is not the problem or focus of this question. What I am asking for is a Python script that sets my desired proxy environment variables. I want to be able to type into my terminal SET after I run the Python script and see the http_proxy=... to verify that the environment-variable-setting Python script worked. I have tried

import os
os.system['SET http_proxy=user:[email protected]:port']

and

import os
os.environ["http_proxy"]="user:[email protected]:port

If you have any further questions, do not hesitate to leave a comment.

Thank you.

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
Julian Rachman
  • 575
  • 3
  • 15

1 Answers1

0

in my case this work fine:

os.system(f'setx TOKEN "{env}" /M')

where os.system execute line in cmd and setx setup system env