I am using below python code to reset the environment variable http_proxy
in Linux CentOS 6, but it is not unsetting the variable for the rest of the Python script.
Code:
import os
print "Unsetting http..."
os.system("unset http_proxy")
os.system("echo $http_proxy")
print "http is reset"
Output:
Unsetting http...
http://web-proxy.xxxx.xxxxxxx.net:8080
http is reset
Process finished with exit code 0
Best Answer
Each invocation of
os.system()
runs in its own subshell, with its own fresh environment:You are unsetting the
http_proxy
variable, but then your subshell has completed executing the command (to wit:unset
), and terminates. You then start a new subshell with a new environment in which to runecho
.I believe what you are trying to do is
del os.environ['http_proxy']
, oros.environ.pop('http_proxy')
if you want to ensure there is nohttp_proxy
environment variable whether or not one previously existed: