The following calls create two separate shell processes:

os.system('unset http_proxy')
os.system('curl https://example.com/')

The first shell removes a variable from its own environment and exits. The Python process still has the original value. The second shell inherits it again.

Give the child the environment you intended

When only one command should run without inherited proxy variables, copy Python's environment and pass the copy to the child:

import os
import subprocess

env = os.environ.copy()
for name in ('http_proxy', 'https_proxy', 'all_proxy',
             'HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY'):
    env.pop(name, None)
subprocess.run(['curl', '--proxy', '', 'https://example.com/'],
               env=env, check=True)

The explicit empty curl proxy setting also overrides proxy selection from curl's own configuration. The environment copy preserves other values the command may need. Passing an empty environment instead can remove executable search paths and unrelated application configuration.

For subsequent operations in the Python process itself, change os.environ deliberately. That affects what newly created children inherit; it does not rewrite the parent terminal's environment or necessarily reconfigure HTTP clients that have already captured their settings.

The subprocess API documents the env argument, and os.environ describes Python's process environment. These scopes are the reason a shell command can report success while the next request still uses the old proxy.

Finally, check the client you're actually running. Environment variables are one configuration input. An explicit proxy option or an application's own configuration can continue to choose a proxy after those variables are gone.

Related articles