How to reset system proxy using pyhton code
Thomas Jollans
tjol at tjol.eu
Mon Feb 19 04:46:27 EST 2018
On 2018-02-19 09:57, Sum J wrote:
> Hi,
>
> I am using below python code (Python 2.7) to reset the proxy of my Ubuntu
> (Cent OS 6) system, but I am unable to reset the proxy:
I'm sure you know this, but CentOS and Ubuntu are two different things.
>
> Code :
> import os
> print "Unsetting http..."
> os.system("unset http_proxy")
> os.system("echo $http_proxy")
> print "http is reset"
Please pay attention to indentation when pasting Python code. I know
what you mean, but as such this code wouldn't even run.
>
> Output :
> Unsetting http...
> http://web-proxy.xxxx.xxxxxxx.net:8080
> http is reset
> Process finished with exit code 0
>
> It should not return ' http://web-proxy.xxxx.xxxxxxx.net:8080 ' in output.
>
> I run the same unset command from terminal , then I see that proxy is
> reset:
>
> [trex at sumlnxvm ~]$ unset $HTTP_PROXY
> [trex at sumlnxvm ~]$ echo $HTTP_PROXY
It is not possible to modify a parent process's environment from within
a child process. Can I interest you in a shell function or alias?
If you want to remove the environment variable for future processes you
start from your python script, simply modify os.environ. For example:
(using an environment variable I actually have on my system)
% cat del_env.py
import os
os.system('echo desktop $XDG_SESSION_DESKTOP')
print('removing')
del os.environ['XDG_SESSION_DESKTOP']
os.system('echo desktop $XDG_SESSION_DESKTOP')
% python del_env.py
desktop gnome
removing
desktop
% echo $XDG_SESSION_DESKTOP
gnome
-- Thomas
>
> [trex at sumlnxvm ~]$
>
>
> Please suggest how to reset system proxy using Python Code
>
> Regards,
> Sumit
>
More information about the Python-list
mailing list