Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular http requests via UrlRequest fail on Android #6946

Closed
idevo89 opened this issue Jun 16, 2020 · 3 comments
Closed

Regular http requests via UrlRequest fail on Android #6946

idevo89 opened this issue Jun 16, 2020 · 3 comments

Comments

@idevo89
Copy link

idevo89 commented Jun 16, 2020

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

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

TypeError("__init__() got an unexpected keyword argument 'context'")
@AndreMiras
Copy link
Member

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?

@matham matham added the awaiting-reply Waiting for reply from issue opener, will be closed if no reply label Jun 16, 2020
@idevo89
Copy link
Author

idevo89 commented Jun 17, 2020

It is the same for v2.0.0rc3. I omitted the try-exception around

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.

if platform in ['android', 'ios']:

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'

@no-response no-response bot removed the awaiting-reply Waiting for reply from issue opener, will be closed if no reply label Jun 17, 2020
@AndreMiras
Copy link
Member

AndreMiras commented Jun 17, 2020

Thanks for the trace, from quick checking I think the problem occurs with HTTPConnection class only which indeed doesn't seem to accept a context while the HTTPSConnection does.

From reading the code, I think this is happening because we no always provide the CA file, refs #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

AndreMiras added a commit to AndreMiras/kivy that referenced this issue Jun 18, 2020
Don't pass a `context` keyword argument for `HTTPConnection`.
The error was:
```
 TypeError: __init__() got an unexpected keyword argument 'context'
 ```
AndreMiras added a commit that referenced this issue Jun 18, 2020
…_file_non_https_scheme

Ignore ca_file on http scheme, fixes #6946
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants