title: Why it is possible to suppress InsecureRequestWarning from within the code with PyCharm and not from a shell
body: <p>I am using <a href="https://github.com/kubernetes-client/python" rel="nofollow noreferrer">kuberentes-python client</a> to send queries to Kubernetes cluster.  </p>
  
  <p>I am using only a bearer token without certificate to send the API requests. Therefore, the connection cannot be verified - insecure connection and I am getting warnings:  </p>
  
  <pre><code>/usr/local/lib/python3.5/dist-packages/urllib3/connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
    InsecureRequestWarning)
  </code></pre>
  
  <p>I know how to suppress these messages and there is a <a href="https://stackoverflow.com/questions/27981545/suppress-insecurerequestwarning-unverified-https-request-is-being-made-in-pytho">way to do it</a>.  </p>
  
  <p>I added in the code the following lines:  </p>
  
  <pre><code>import urllib3
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  </code></pre>
  
  <p>It worked !  I don't get the warnings anymore in PyCharm.<br>
  But when I ran the python code from the shell <code>python3 myapp.py</code>, the warning were still exist.  </p>
  
  <p>I have a workaround for that: <code>export PYTHONWARNINGS="ignore:Unverified HTTPS request"</code> but it works only if you run it from the shell before running the script and I preferred it to be from the code.<br>
  My questions is <strong>why the warnings were suppressed with PyCharm but not from the shell</strong> ?</p>
  
  <p>This is my code if you want to test it (just change the host and token):  </p>
  
  <pre><code>from kubernetes import client
  import os
  from kubernetes.client import Configuration
  
  SERVICE_TOKEN_FILENAME = "/home/ubuntu/root-token"
  
  
  class InClusterConfigLoader(object):
  
      def __init__(self, token_filename):
          self._token_filename = token_filename
  
      def load_and_set(self):
          self._load_config()
          self._set_config()
  
      def _load_config(self):
          self.host = "https://10.0.62.0:8443"
  
          if not os.path.isfile(self._token_filename):
              print("Service token file does not exists.")
  
          with open(self._token_filename) as f:
              self.token = f.read().rstrip('\n')
              if not self.token:
                  print("Token file exists but empty.")
  
  
      def _set_config(self):
          configuration = Configuration()
          configuration.host = self.host
          configuration.ssl_ca_cert = None
          configuration.verify_ssl = False
          configuration.api_key['authorization'] = "bearer " + self.token
          Configuration.set_default(configuration)
  
  def load_incluster_config():
      InClusterConfigLoader(token_filename=SERVICE_TOKEN_FILENAME).load_and_set()
  
  import urllib3
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  
  load_incluster_config()
  
  api = client.CoreV1Api()
  service_accounts = api.list_service_account_for_all_namespaces()
  
  print(len(service_accounts.items))
  </code></pre>