Repository: kivy/kivy

Issue:
Regular http requests via UrlRequest fail on Android
**Software Versions**
* Python: v3.8.1
* OS: Android 9 API29
* Kivy: v2.0.0rc2
* Kivy installation method: python-for-android develop

**Describe the bug**
Since #6703, regular http requests via urlrequest no longer work on android. The on_error function of urlrequest is called, while on desktop it is successful. Going back to kivy v2.0.0rc1 fixes it, but this version has broken https.

**Expected behavior**
Successful regular http requests.

**To Reproduce**
```python
from kivy.app import runTouchApp
from kivy.uix.widget import Widget
from kivy.network.urlrequest import UrlRequest


class Test(Widget):
    def __init__(self, **kwargs):
        super(Test, self).__init__(**kwargs)
        UrlRequest(
            url='http://lipsum.com/',
            on_error=lambda *args: print('error:', args),
            on_failure=lambda *args: print('fail:', args),
            on_redirect=lambda *args: print('redir:', args),
            on_success=lambda *args: print('success:', args)
        )
        UrlRequest(
            url='https://lipsum.com/',
            on_error=lambda *args: print('error:', args),
            on_failure=lambda *args: print('fail:', args),
            on_redirect=lambda *args: print('redir:', args),
            on_success=lambda *args: print('success:', args)
        )


runTouchApp(Test())

```

**Code and Logs and screenshots**
```python
TypeError("__init__() got an unexpected keyword argument 'context'")
```



Discussion:
Thanks for the report. Please share the full stacktrace as it often helps developers to spot the exact issue more quickly.
Also could you try on the  2.0.0rc3 that was released recently?
It is the same for v2.0.0rc3. I omitted the try-exception around
```python
result, resp = self._fetch_url(url, req_body, req_headers, q)
```
and added 'win' to line 219 in urlrequest to simulate the error on desktop and get a traceback.
https://github.com/kivy/kivy/blob/ab58fbecea6ae1ee4f8f465d9eaad2b41bdd6f65/kivy/network/urlrequest.py#L219


```python
Exception in thread Thread-1:
 Traceback (most recent call last):
   File "C:\Program Files (x86)\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
     self.run()
   File "C:\Program Files (x86)\Python38-32\lib\site-packages\kivy\network\urlrequest.py", line 253, in run
     result, resp = self._fetch_url(url, req_body, req_headers, q)
   File "C:\Program Files (x86)\Python38-32\lib\site-packages\kivy\network\urlrequest.py", line 360, in _fetch_url
     req = cls(host, port, **args)
 TypeError: __init__() got an unexpected keyword argument 'context'
```
Thanks for the trace, from quick checking I think the problem occurs with [`HTTPConnection`](https://docs.python.org/3/library/http.client.html#http.client.HTTPConnection) class only which indeed doesn't seem to accept a context while the [`HTTPSConnection`](https://docs.python.org/3/library/http.client.html#http.client.HTTPSConnection) does.

From reading the code, I think this is happening because we no always provide the CA file, refs https://github.com/kivy/kivy/pull/6703 then we enter in this case https://github.com/kivy/kivy/blob/2.0.0rc3/kivy/network/urlrequest.py#L337 which generates the context. So probably an easy fix would be to also check for `parse.scheme == 'https'` in this if as well. I may make a PR + test later this week

Resolving patch:
diff --git a/kivy/network/urlrequest.py b/kivy/network/urlrequest.py
--- a/kivy/network/urlrequest.py
+++ b/kivy/network/urlrequest.py
@@ -334,7 +334,8 @@ def _fetch_url(self, url, body, headers, q):
         if timeout is not None:
             args['timeout'] = timeout
 
-        if ca_file is not None and hasattr(ssl, 'create_default_context'):
+        if (ca_file is not None and hasattr(ssl, 'create_default_context') and
+                parse.scheme == 'https'):
             ctx = ssl.create_default_context(cafile=ca_file)
             ctx.verify_mode = ssl.CERT_REQUIRED
             args['context'] = ctx


Test patch:
diff --git a/kivy/tests/test_urlrequest.py b/kivy/tests/test_urlrequest.py
--- a/kivy/tests/test_urlrequest.py
+++ b/kivy/tests/test_urlrequest.py
@@ -130,3 +130,29 @@ def test_auth_auto(kivy_clock):
     ensure_called_from_thread(queue)
     check_queue_values(queue)
     assert queue[-1][2] == ({'authenticated': True, 'user': 'user'}, )
+
+
+@pytest.mark.skipif(os.environ.get('nonetwork'), reason="no network")
+@pytest.mark.parametrize("scheme", ("http", "https"))
+def test_ca_file(kivy_clock, scheme):
+    """Passing a `ca_file` should not crash on http scheme, refs #6946"""
+    from kivy.network.urlrequest import UrlRequest
+    import certifi
+    obj = UrlRequestQueue([])
+    queue = obj.queue
+    req = UrlRequest(
+        f"{scheme}://httpbin.org/get",
+        on_success=obj._on_success,
+        on_progress=obj._on_progress,
+        on_error=obj._on_error,
+        on_redirect=obj._on_redirect,
+        ca_file=certifi.where(),
+        debug=True
+    )
+    wait_request_is_finished(kivy_clock, req)
+
+    if req.error and req.error.errno == 11001:
+        pytest.skip('Cannot connect to get address')
+
+    ensure_called_from_thread(queue)
+    check_queue_values(queue)