Repository: spyder-ide/spyder

Issue:
Spyder 5.0.4 crashes with proxy error to kite.com
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [ x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [ ] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [ x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [ ] Tried basic troubleshooting (if a bug/error)
    * [ x] Restarted Spyder
    * [ x] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x ] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
Spyder 5.0.4 crashes with proxy error to kite.com and "internal console not found.


### What steps reproduce the problem?

1. Upgrade Spyder from 5.0.3 to 5.0.4.
2. Start Spyder, it crashes.
3. Downgrade to 5.0.3, everything works.

### What is the expected output? What do you see instead?



### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback

Traceback (most recent call last):
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/urllib3/connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/urllib3/connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/urllib3/connection.py", line 500, in _connect_tls_proxy
    return ssl_wrap_socket(
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 428, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 472, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ConnectionResetError: [Errno 54] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/urllib3/util/retry.py", line 574, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='release.kite.com', port=443): Max retries exceeded with url: /dls/mac/current (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(54, 'Connection reset by peer')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 2132, in create_window
    main.setup()
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 903, in setup
    plugin_instance = plugin_class(self, configuration=CONF)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 236, in __init__
    raise e
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 232, in __init__
    self._instantiate_and_register_provider(Provider)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/plugins/completion/plugin.py", line 754, in _instantiate_and_register_provider
    provider_instance = Provider(self, provider_config['values'])
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/plugins/completion/providers/kite/provider.py", line 83, in __init__
    self.setup_menus()
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/plugins/completion/providers/kite/provider.py", line 235, in setup_menus
    installers_available = check_kite_installers_availability()
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/plugins/completion/providers/kite/utils/status.py", line 117, in check_kite_installers_availability
    req = requests.head(url)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/requests/api.py", line 104, in head
    return request('head', url, **kwargs)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/requests/adapters.py", line 510, in send
    raise ProxyError(e, request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='release.kite.com', port=443): Max retries exceeded with url: /dls/mac/current (Caused by ProxyError('Cannot connect to proxy.', ConnectionResetError(54, 'Connection reset by peer')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/gvizkel/python38/bin/spyder", line 8, in <module>
    sys.exit(main())
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/app/start.py", line 226, in main
    mainwindow.main(options, args)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 2282, in main
    mainwindow = create_window(app, splash, options, args)
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 2134, in create_window
    if main.console is not None:
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 1156, in __getattr__
    return self.get_plugin(self._INTERNAL_PLUGINS_MAPPING[attr])
  File "/Users/gvizkel/python38/lib/python3.8/site-packages/spyder/app/mainwindow.py", line 169, in get_plugin
    raise SpyderAPIError(
spyder.api.exceptions.SpyderAPIError: Plugin "internal_console" not found!

```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 5.0.4
* Python version: 3.8.9
* Qt version: 
* PyQt version: 5.12.3
* Operating System name/version: MacOS 10.15.7

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```
PASTE DEPENDENCIES HERE
```



Discussion:
Hi @gvizkelethy,

This error is happening at the startup or did you ran something? Also, how are you upgrading Spyder?
This happens when I start Spyder from a terminal window. It does not matter if I start in the foreground or the background. I upgraded Spyder with pip, I do not have the anaconda environment. 
I get a similar error with 5.0.4 where it fails to launch if I am not connected to the internet. Connected it works.
I am connected to the internet but through a firewall. The proxy settings work for everything, even for pip except for Spyder. It looks like it is trying to connect to the wrong proxy. Is there a way to check what proxy it is trying to connect? And why does Spyder need an internet connection? Can I turn it off?
@gvizkelethy, how did you set your proxy settings so that pip can use them? Are you using environment variables for that?
Yes, I am using environment variables:
PIP_PROXY=https://proxy.sandia.gov:80
http_proxy=http://proxy.sandia.gov:80
https_proxy=https://proxy.sandia.gov:80
Ok, thanks for the confirmation @gvizkelethy.

We'll fix this problem and release 5.0.5 right away.
According to the requests documentation, the variables set by @gvizkelethy should work as expected, as requests is already picking them. In this case, the error is related to the proxy communication and not with Spyder, we should introduce a Try/Except block to prevent these kind of errors.

Resolving patch:
diff --git a/spyder/plugins/completion/providers/kite/utils/status.py b/spyder/plugins/completion/providers/kite/utils/status.py
--- a/spyder/plugins/completion/providers/kite/utils/status.py
+++ b/spyder/plugins/completion/providers/kite/utils/status.py
@@ -114,11 +114,15 @@ def check_kite_installers_availability():
     elif sys.platform == 'darwin':
         url = MAC_URL
 
-    req = requests.head(url)
-    available = req.ok
-    if req.ok:
-        if req.is_redirect:
-            loc = req.headers['Location']
-            req = requests.head(loc)
-            available = req.ok
+    available = False
+    try:
+        req = requests.head(url)
+        available = req.ok
+        if req.ok:
+            if req.is_redirect:
+                loc = req.headers['Location']
+                req = requests.head(loc)
+                available = req.ok
+    except Exception:
+        pass
     return available


Test patch: