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

Fix building ssl for python3 #1217

Closed
wants to merge 1 commit into from
Closed

Conversation

agilewalker
Copy link

Pull request #1195 commits squashed and rebased onto master.

@bauerj
Copy link
Contributor

bauerj commented Jan 15, 2018

Why was this closed?

@ysangkok
Copy link

ysangkok commented Mar 3, 2018

@Zen-CODE Do you know why this was closed?

@inclement
Copy link
Member

@ysangkok It was closed by the OP, I don't know why.

@bauerj
Copy link
Contributor

bauerj commented Mar 3, 2018

@agilewalker Do you know why this was closed?

@Zen-CODE
Copy link
Member

Zen-CODE commented Mar 4, 2018

Perhaps the question for ask is whether #1195 fixes the issue? And if so, why has it not been merged? It seems most likely that the PR was just never merged...

Can anyone confirm that pull requests fixes the issue?

@ysangkok
Copy link

ysangkok commented Mar 4, 2018

It does fix the issue, we are using it in Electrum. See the readme in https://github.com/spesmilo/electrum/tree/master/gui/kivy

@Zen-CODE
Copy link
Member

Zen-CODE commented Mar 4, 2018

@ysangkok. Okay, I've re-opened the RP. Will test and merge if I don't see any problems. Thanks

@Zen-CODE
Copy link
Member

Zen-CODE commented Mar 6, 2018

Even using the PR above (and setting the p4a.source_dir to point to there, I don't get a build error but when running get

ImportError: No module named '_ssl'

If I try your instructions, when I try to checkout the specified commit, I get:

pathspec 'a036f4442b6a23' did not match any

@ysangkok
Copy link

ysangkok commented Mar 6, 2018

Weird that you can't find the commit, did you git fetch from agilewalker? The commit is here: agilewalker@a036f4442b6a23 . I have to ponder on the other issue.

EDIT: actually, @SomberNight let me know that that commit is in kivy/python-for-android too. So I really can't understand how you couldn't check it out.

@Zen-CODE
Copy link
Member

Zen-CODE commented Mar 8, 2018

My bad. Okay, I've got it checked out but I still get the "ImportError: No module named '_ssl'" when doing an import ssl. I am using python 3.5 though. I see the PR contains a python3.6 patch, so possibly it only works for 3.6?

@inclement
Copy link
Member

Following the recent discussion on irc, I think the following things need to be done for this to be merged:

  1. Rebasing on master again (obviously)
  2. It needs testing via Travis
  3. I think the build order code at https://github.com/kivy/python-for-android/pull/1217/files#diff-7029dba21bb853e1d7019a7a98586ee9R194 should be restructured to not use arbitrary numbers, so that it's clearer what's going on.

I was going to start on this, but hit some other build problems with p4a, which I'm looking into first.

@ghost
Copy link

ghost commented Nov 5, 2018

Since this pull request has a minor conflict with current master, I rebased it while resolving the conflict:

https://github.com/JonasT/python-for-android/tree/tlsfix

(just in case anyone else needs this)

@ghost
Copy link

ghost commented Nov 6, 2018

Edit: nvm I was silly and forgot the internet permission. pull request seems to work fine at least as of now

@pat1
Copy link

pat1 commented Nov 9, 2018

I have checked JonasT fork and it works for me. I hope in a merge.

@ghost
Copy link

ghost commented Nov 20, 2018

@pat1 I think the plan for the future is that python3crystax will be fully abandoned for a direct upstream python 3 build. With this, the missing standard library module issues, including this _ssl module, should be fixed. So I assume (but the others will need to correct me on this) that this will most likely not be merged in favor of fixing the whole python3crystax situation instead.

@tito
Copy link
Member

tito commented Nov 20, 2018

I've an rework openssl recipes that works on latest release and ndk, will open PR today.
It will outdate this one.

@homdx
Copy link

homdx commented Nov 20, 2018

@pat1 I think the plan for the future is that python3crystax will be fully abandoned for a direct upstream python 3 build. With this, the missing standard library module issues, including this _ssl module, should be fixed. So I assume (but the others will need to correct me on this) that this will most likely not be merged in favor of fixing the whole python3crystax situation instead.

I probe compile test app:

https://stackoverflow.com/questions/49884548/how-to-run-kivy-and-flask-apps-together

with buildozer==0.0.34:

[app]
requirements = kivy,git+https://github.com/JonasT/python-for-android.git,pymysql,python3crystax==3.6,crypto,Flask,werkzeug,jinja2,markupsafe,openssl
android.ndk = 17c
android.ndk_path = /home/user/.buildozer/crystax-ndk-10.3.2
android.arch = armeabi-v7a

Error in my phone: (log from adb)

files/app/crystax_python/stdlib.zip/ssl.py", line 101, in
I/python ( 4918): ModuleNotFoundError: No module named '_ssl'
I/python ( 4918): WARNING:kivy:stderr: ModuleNotFoundError: No module named '_ssl'
I/python ( 4918): Python for android ended.

@ghost
Copy link

ghost commented Nov 20, 2018

@homdx have you used the "tlsfix" branch? the "master" branch of the JonasT/python-for-android repo contains whatever, but not this pull request

@JohnBuckleyGitHub
Copy link

JohnBuckleyGitHub commented Jan 2, 2019 via email

@JohnBuckleyGitHub
Copy link

JohnBuckleyGitHub commented Jan 2, 2019 via email

@ghost
Copy link

ghost commented Jan 2, 2019

@johnbolia I vaguely remember some issue with building Crystax + TLS with NDK API/minimum API 21. I use target API 26 + ndk/minimum 19 with Crystax personally and that works fine. Can you attach your build error? (don't use e-mail, respond using the web interface and attach the thing there - then it should show up)

Regarding --workspace, it's just a volume yes. It needs a folder path as a parameter, which is the folder that will then be mapped inside as ~/workspace. Ideally, that folder contains your project itself, that saves you the effort to download it separately each time

@ghost
Copy link

ghost commented Jan 2, 2019

For what it's worth, we're also like 3 merges away from obsoleting Crystax I would think. So in 1-2 weeks this whole tlsfix & crystax business might have solved itself 🤷‍♀️ lol

@JohnBuckleyGitHub
Copy link

@Jonast I have attached the screen output

Apologies to the issue thread for going so far off topic, I was on email and forgot all this was posted.
p4a screen output.txt

@ghost
Copy link

ghost commented Jan 2, 2019

@Jonast I have attached the screen output

Ah, it might want clang and only gcc is around. Should be easy to fix, nevertheless I remember CrystaX having some issues with higher minimum(!) API levels so I'm not sure if that environment is very useful anyway (I added a few just for testing mainly)

I loaded the container p4a-py3crystax-api26ndk19 and tried the example. Unfortunately it requires api 21+

Do you require that as a minimum API though? This is almost never necessary, so it sounds to me like you might maybe just want to use p4a-py3crystax-api26ndk19 instead

@homdx
Copy link

homdx commented Jan 11, 2019

@Jonast I checked with new deps #apt install -y libffi-dev libssl-dev and latest branch master of p4a:

New logs:

I/python  ( 4580): Android kivy bootstrap done. __name__ is __main__
I/python  ( 4580): AND: Ran string
I/python  ( 4580): Run user program, change dir and execute entrypoint
I/python  ( 4580): main.py
I/python  ( 4580): [WARNING] [Config      ] Older configuration version detected (0 instead of 20)
I/python  ( 4580): [WARNING] [Config      ] Upgrading configuration in progress.
I/python  ( 4580): [INFO   ] [Logger      ] Record log in /data/data/com.example.test/files/app/.kivy/logs/kivy_19-01-11_0.txt
I/python  ( 4580): [INFO   ] [Kivy        ] v1.10.1
I/python  ( 4580): [INFO   ] [Python      ] v3.7.1 (default, Jan 11 2019, 17:30:45) 
I/python  ( 4580): [Clang 6.0.2 (https://android.googlesource.com/toolchain/clang 183abd29fc496f55
I/python  ( 4580): [INFO   ] [Factory     ] 194 symbols loaded
I/python  ( 4580): [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
I/python  ( 4580): [INFO   ] [Window      ] Provider: sdl2
I/python  ( 4580): [INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
I/python  ( 4580): [INFO   ] [GL          ] Backend used <gl>
I/python  ( 4580): [INFO   ] [GL          ] OpenGL version <b'OpenGL ES 3.1 build 1.4@3300288'>
I/python  ( 4580): [INFO   ] [GL          ] OpenGL vendor <b'Imagination Technologies'>
I/python  ( 4580): [INFO   ] [GL          ] OpenGL renderer <b'PowerVR Rogue G6200'>
I/python  ( 4580): [INFO   ] [GL          ] OpenGL parsed version: 3, 1
I/python  ( 4580): [INFO   ] [GL          ] Texture max size <8192>
I/python  ( 4580): [INFO   ] [GL          ] Texture max units <16>
I/python  ( 4580): [INFO   ] [Window      ] auto add sdl2 input provider
I/python  ( 4580): [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
I/python  ( 4580):  main.py:172: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
I/python  ( 4580):    import imp
I/python  ( 4580): [WARNING] [Base        ] Unknown <android> provider
I/python  ( 4580): [INFO   ] [Base        ] Start application main loop
I/python  ( 4580): [INFO   ] [GL          ] NPOT texture support is available
I/python  ( 4580): [INFO   ] [Text        ] Provider: sdl2
I/python  ( 4580): [WARNING] [Accordion   ] not enough space for displaying all children
I/python  ( 4580): [WARNING] [Accordion   ] need 264px, got 0px
I/python  ( 4580): [WARNING] [Accordion   ] layout aborted.
I/python  ( 4580): [INFO   ] [Loader      ] using a thread pool of 2 workers
I/python  ( 4580): [ERROR  ] [Loader      ] Failed to load image <https://kushaldas.in/images/pyconin15-3.jpg>
I/python  ( 4580): Traceback (most recent call last):
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 1317, in do_open
I/python  ( 4580):     encode_chunked=req.has_header('Transfer-encoding'))
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1229, in request
I/python  ( 4580):     self._send_request(method, url, body, headers, encode_chunked)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1275, in _send_request
I/python  ( 4580):     self.endheaders(body, encode_chunked=encode_chunked)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1224, in endheaders
I/python  ( 4580):     self._send_output(message_body, encode_chunked=encode_chunked)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1016, in _send_output
I/python  ( 4580):     self.send(msg)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 956, in send
I/python  ( 4580):     self.connect()
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1392, in connect
I/python  ( 4580):     server_hostname=server_hostname)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/ssl.py", line 412, in wrap_socket
I/python  ( 4580):     session=session
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/ssl.py", line 853, in _create
I/python  ( 4580):     self.do_handshake()
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/ssl.py", line 1117, in do_handshake
I/python  ( 4580):     self._sslobj.do_handshake()
I/python  ( 4580): ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)
I/python  ( 4580): During handling of the above exception, another exception occurred:
I/python  ( 4580): Traceback (most recent call last):
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/loader.py", line 317, in _load_urllib
I/python  ( 4580):     fd = urllib_request.urlopen(filename)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 222, in urlopen
I/python  ( 4580):     return opener.open(url, data, timeout)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 525, in open
I/python  ( 4580):     response = self._open(req, data)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 543, in _open
I/python  ( 4580):     '_open', req)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 503, in _call_chain
I/python  ( 4580):     result = func(*args)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 1360, in https_open
I/python  ( 4580):     context=self._context, check_hostname=self._check_hostname)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 1319, in do_open
I/python  ( 4580):     raise URLError(err)
I/python  ( 4580): urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)>
I/python  ( 4580): [ERROR  ] [Loader      ] Failed to load image <https://paste.opensuse.org/images/85253798.png>
I/python  ( 4580): Traceback (most recent call last):
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 1317, in do_open
I/python  ( 4580):     encode_chunked=req.has_header('Transfer-encoding'))
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1229, in request
I/python  ( 4580):     self._send_request(method, url, body, headers, encode_chunked)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1275, in _send_request
I/python  ( 4580):     self.endheaders(body, encode_chunked=encode_chunked)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1224, in endheaders
I/python  ( 4580):     self._send_output(message_body, encode_chunked=encode_chunked)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1016, in _send_output
I/python  ( 4580):     self.send(msg)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 956, in send
I/python  ( 4580):     self.connect()
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/http/client.py", line 1392, in connect
I/python  ( 4580):     server_hostname=server_hostname)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/ssl.py", line 412, in wrap_socket
I/python  ( 4580):     session=session
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/ssl.py", line 853, in _create
I/python  ( 4580):     self.do_handshake()
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/ssl.py", line 1117, in do_handshake
I/python  ( 4580):     self._sslobj.do_handshake()
I/python  ( 4580): ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)
I/python  ( 4580): During handling of the above exception, another exception occurred:
I/python  ( 4580): Traceback (most recent call last):
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/loader.py", line 317, in _load_urllib
I/python  ( 4580):     fd = urllib_request.urlopen(filename)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 222, in urlopen
I/python  ( 4580):     return opener.open(url, data, timeout)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 525, in open
I/python  ( 4580):     response = self._open(req, data)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 543, in _open
I/python  ( 4580):     '_open', req)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 503, in _call_chain
I/python  ( 4580):     result = func(*args)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 1360, in https_open
I/python  ( 4580):     context=self._context, check_hostname=self._check_hostname)
I/python  ( 4580):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib/request.py", line 1319, in do_open
I/python  ( 4580):     raise URLError(err)
I/python  ( 4580): urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1051)>

and

I/python  ( 4156): [INFO   ] [Python      ] v2.7.15 (default, Jan 11 2019, 17:41:48) 
I/python  ( 4156): [GCC 4.2.1 Compatible Android (4691093 based on r316199) Clang 6.0.2 (https://a
I/python  ( 4156): [INFO   ] [Factory     ] 194 symbols loaded
I/python  ( 4156): [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
I/python  ( 4156): [INFO   ] [Window      ] Provider: sdl2
I/python  ( 4156): [INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
I/python  ( 4156): [INFO   ] [GL          ] Backend used <gl>
I/python  ( 4156): [INFO   ] [GL          ] OpenGL version <OpenGL ES 3.1 build 1.4@3300288>
I/python  ( 4156): [INFO   ] [GL          ] OpenGL vendor <Imagination Technologies>
I/python  ( 4156): [INFO   ] [GL          ] OpenGL renderer <PowerVR Rogue G6200>
I/python  ( 4156): [INFO   ] [GL          ] OpenGL parsed version: 3, 1
I/python  ( 4156): [INFO   ] [GL          ] Texture max size <8192>
I/python  ( 4156): [INFO   ] [GL          ] Texture max units <16>
I/python  ( 4156): [INFO   ] [Window      ] auto add sdl2 input provider
I/python  ( 4156): [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
I/python  ( 4156): [WARNING] [Base        ] Unknown <android> provider
I/python  ( 4156): [INFO   ] [Base        ] Start application main loop
I/python  ( 4156): [INFO   ] [GL          ] NPOT texture support is available
I/python  ( 4156): [INFO   ] [Text        ] Provider: sdl2
I/python  ( 4156): [INFO   ] [Base        ] Leaving application in progress...
I/python  ( 4156):  Traceback (most recent call last):
I/python  ( 4156):    File "main.py", line 193, in <module>
I/python  ( 4156):      PyConApp().run()
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/app.py", line 826, in run
I/python  ( 4156):      runTouchApp()
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/base.py", line 502, in runTouchApp
I/python  ( 4156):      EventLoop.window.mainloop()
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/core/window/window_sdl2.py", line 727, in mainloop
I/python  ( 4156):      self._mainloop()
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/core/window/window_sdl2.py", line 460, in _mainloop
I/python  ( 4156):      EventLoop.idle()
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/base.py", line 337, in idle
I/python  ( 4156):      Clock.tick()
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/clock.py", line 581, in tick
I/python  ( 4156):      self._process_events()
I/python  ( 4156):    File "kivy/_clock.pyx", line 384, in kivy._clock.CyClockBase._process_events
I/python  ( 4156):    File "kivy/_clock.pyx", line 414, in kivy._clock.CyClockBase._process_events
I/python  ( 4156):    File "kivy/_clock.pyx", line 412, in kivy._clock.CyClockBase._process_events
I/python  ( 4156):    File "kivy/_clock.pyx", line 167, in kivy._clock.ClockEvent.tick
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/animation.py", line 352, in _update
I/python  ( 4156):      self.stop(widget)
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/animation.py", line 217, in stop
I/python  ( 4156):      self.dispatch('on_complete', widget)
I/python  ( 4156):    File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
I/python  ( 4156):    File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
I/python  ( 4156):    File "kivy/_event.pyx", line 1138, in kivy._event.EventObservers._dispatch
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/uix/screenmanager.py", line 419, in _on_complete
I/python  ( 4156):      self.screen_in.dispatch('on_enter')
I/python  ( 4156):    File "kivy/_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch
I/python  ( 4156):    File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
I/python  ( 4156):    File "kivy/_event.pyx", line 1098, in kivy._event.EventObservers._dispatch
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/lang/builder.py", line 64, in custom_callback
I/python  ( 4156):      exec(__kvlang__.co_value, idmap)
I/python  ( 4156):    File "<string>", line 78, in <module>
I/python  ( 4156):    File "main.py", line 178, in load_screen
I/python  ( 4156):      manager.add_widget(sc)
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/uix/screenmanager.py", line 993, in add_widget
I/python  ( 4156):      self.current = screen.name
I/python  ( 4156):    File "kivy/properties.pyx", line 483, in kivy.properties.Property.__set__
I/python  ( 4156):    File "kivy/properties.pyx", line 524, in kivy.properties.Property.set
I/python  ( 4156):    File "kivy/properties.pyx", line 579, in kivy.properties.Property.dispatch
I/python  ( 4156):    File "kivy/_event.pyx", line 1214, in kivy._event.EventObservers.dispatch
I/python  ( 4156):    File "kivy/_event.pyx", line 1120, in kivy._event.EventObservers._dispatch
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/uix/screenmanager.py", line 1056, in on_current
I/python  ( 4156):      screen.dispatch('on_enter')
I/python  ( 4156):    File "kivy/_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
I/python  ( 4156):    File "/data/data/com.example.test/files/app/uix/screens/screenschedule.py", line 175, in on_enter
I/python  ( 4156):      from network import get_data
I/python  ( 4156):    File "/data/data/com.example.test/files/app/network/__init__.py", line 3, in <module>
I/python  ( 4156):      from kivy.network.urlrequest import UrlRequest
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/network/urlrequest.py", line 67, in <module>
I/python  ( 4156):      from httplib import HTTPConnection
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/httplib.py", line 72, in <module>
I/python  ( 4156):    File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/socket.py", line 47, in <module>
I/python  ( 4156):  ImportError: dlopen failed: cannot locate symbol "gethostbyaddr_r" referenced by "_socket.so"...
I/python  ( 4156): Python for android ended.
I/DEBUG   ( 4201):     #00 pc 0012856c  /data/app/com.example.test-1/lib/arm/libpython2.7.so

@homdx
Copy link

homdx commented Jan 11, 2019

Great)) You reproduce new bug, like this:
#1501

Then I launch app in phone: give error:

Error: dlopen failed: could not load library "libpython2.7.so.1.0" needed by "libmain.so", caused by library "libpython2.7.so.1.0" not found

Step for reproduce need Docker with env, provided by @Jonast
https://github.com/JonasT/p4a-build-spaces

Start with you branch p4a:
$./p4aspaces shell p4a-py3-api28ndk21 --p4a=https://github.com/opacam/python-for-android/archive/fix-python2-gethost.zip
In docker:

git clone https://github.com/homdx/pydelhi_mobile
cd pyd*
git checkout api28
apt-get install nano --yes
nano .p4a

file .p4a
--arch=armeabi-v7a
--name 'Py Delhi'
--package com.example.test
--version 1
--icon data/icon.png
--presplash=../screen.png
--permission=INTERNET
--requirements=python2,android,openssl,kivy==1.10.1,futures,requests

end of file .p4a

now copy this file to folder and build:

cp .p4a pydelhiconf/
cd pydelhiconf
and compile
time p4a apk --private .

And install apk and give errors:)

V/pythonutil(14740): Checking pattern libcrypto.*\.so against libssl1.1.so
V/pythonutil(14740): Checking pattern libcrypto.*\.so against libSDL2_mixer.so
V/pythonutil(14740): Checking pattern libcrypto.*\.so against libSDL2_ttf.so
V/pythonutil(14740): Checking pattern libcrypto.*\.so against libmain.so
V/pythonutil(14740): Checking pattern libcrypto.*\.so against libSDL2.so
V/pythonutil(14740): Checking pattern libcrypto.*\.so against libpython2.7.so
V/pythonutil(14740): Checking pattern libcrypto.*\.so against libcrypto1.1.so
V/pythonutil(14740): Pattern libcrypto.*\.so matched file libcrypto1.1.so
V/pythonutil(14740): Checking pattern libcrypto.*\.so against libSDL2_image.so
V/pythonutil(14740): Loading library: SDL2
V/pythonutil(14740): Loading library: SDL2_image
V/pythonutil(14740): Loading library: SDL2_mixer
V/pythonutil(14740): Loading library: SDL2_ttf
V/pythonutil(14740): Loading library: ssl1.1
V/pythonutil(14740): Loading library: crypto1.1
V/pythonutil(14740): Loading library: python2.7
V/pythonutil(14740): Loading library: python3.5m
V/pythonutil(14740): Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.test-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libpython3.5m.so"
V/pythonutil(14740): Loading library: python3.6m
V/pythonutil(14740): Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.test-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libpython3.6m.so"
V/pythonutil(14740): Loading library: python3.7m
V/pythonutil(14740): Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.test-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libpython3.7m.so"
V/pythonutil(14740): Loading library: main
E/art     (14740): dlopen("/data/app/com.example.test-1/lib/arm/libmain.so", RTLD_LAZY) failed: dlopen failed: could not load library "libpython2.7.so.1.0" needed by "libmain.so"; caused by library "libpython2.7.so.1.0" not found
V/pythonutil(14740): Library loading error: dlopen failed: could not load library "libpython2.7.so.1.0" needed by "libmain.so"; caused by library "libpython2.7.so.1.0" not found
V/pythonutil(14740): An UnsatisfiedLinkError occurred loading main
W/System.err(14740): dlopen failed: could not load library "libpython2.7.so.1.0" needed by "libmain.so"; caused by library "libpython2.7.so.1.0" not found

@opacam
Copy link
Member

opacam commented Jan 11, 2019

Try it now please @homdx, it should work

Note: sorry, I didn't consider the @Jonast's application p4aspaces, my master branch was outdated...I only considered the merge conflicts...

@ghost
Copy link

ghost commented Jan 11, 2019

@opacam use --force-redownload-p4a to disable caching of p4a with p4aspaces (it's not the default so the environment can launch offline if people really want to)

@homdx
Copy link

homdx commented Jan 11, 2019

@opacam use --force-redownload-p4a to disable caching of p4a with p4aspaces (it's not the default so the environment can launch offline if people really want to)

@Jonast i seem to promote your p4a-build-spaces

@homdx
Copy link

homdx commented Jan 11, 2019

@Jonast How increase build speed for p4a ? like $make -j4 ? Thanks)

@opacam
Copy link
Member

opacam commented Jan 11, 2019

I don't think you can speed up the build, this is a todo's thing, as described in issue #1558 by @KeyWeeUsr

@opacam
Copy link
Member

opacam commented Jan 11, 2019

Ei @Jonast, the branch of the fix did not contained the INSTSONAME fix that we discussed soo much....jajaja...I think that is the problem... 😉

@homdx
Copy link

homdx commented Jan 11, 2019

@opacam build and run Python2
logcat:

V/pythonutil(22541): Checking pattern libcrypto.*\.so against libSDL2_image.so
V/pythonutil(22541): Loading library: SDL2
V/pythonutil(22541): Loading library: SDL2_image
V/pythonutil(22541): Loading library: SDL2_mixer
V/pythonutil(22541): Loading library: SDL2_ttf
V/pythonutil(22541): Loading library: ssl1.1
V/pythonutil(22541): Loading library: crypto1.1
V/pythonutil(22541): Loading library: python2.7
V/pythonutil(22541): Loading library: python3.5m
V/pythonutil(22541): Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.test-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libpython3.5m.so"
V/pythonutil(22541): Loading library: python3.6m
V/pythonutil(22541): Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.test-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libpython3.6m.so"
V/pythonutil(22541): Loading library: python3.7m
V/pythonutil(22541): Library loading error: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/com.example.test-1/base.apk"],nativeLibraryDirectories=[/data/app/com.example.test-1/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libpython3.7m.so"
V/pythonutil(22541): Loading library: main
E/art     (22541): dlopen("/data/data/com.example.test/files/app/lib/python2.7/lib-dynload/_io.so", RTLD_LAZY) failed: dlopen failed: library "/data/data/com.example.test/files/app/lib/python2.7/lib-dynload/_io.so" not found
V/pythonutil(22541): Failed to load _io.so or unicodedata.so...but that's okay.
E/art     (22541): dlopen("/data/data/com.example.test/files/app/lib/python2.7/lib-dynload/_ctypes.so", RTLD_LAZY) failed: dlopen failed: library "/data/data/com.example.test/files/app/lib/python2.7/lib-dynload/_ctypes.so" not found
V/pythonutil(22541): Unsatisfied linker when loading ctypes
V/pythonutil(22541): Loaded everything!
I/python  (22541): Initializing Python for Android
I/python  (22541): Changing directory to the one provided by ANDROID_ARGUMENT
I/python  (22541): /data/data/com.example.test/files/app
I/python  (22541): Preparing to initialize python
I/python  (22541): _python_bundle dir exists
I/python  (22541): calculated paths to be...
I/python  (22541): /data/data/com.example.test/files/app/_python_bundle/stdlib.zip:/data/data/com.example.test/files/app/_python_bundle/modules
I/python  (22541): set wchar paths...
I/python  (22541): Initialized python
I/python  (22541): AND: Init threads
I/python  (22541): testing python print redirection
I/python  (22541): ('Android path', ['.', '', '/data/data/com.example.test/files/app/_python_bundle/stdlib.zip', '/data/data/com.example.test/files/app/_python_bundle/modules', '/data/data/com.example.test/files/app/_python_bundle/site-packages'])
I/python  (22541): ('os.environ is', {'ANDROID_APP_PATH': '/data/data/com.example.test/files/app', 'EXTERNAL_STORAGE': '/storage/emulated/legacy', 'LOOP_MOUNTPOINT': '/mnt/obb', 'SYSTEMSERVERCLASSPATH': '/system/framework/services.jar:/system/framework/ethernet-service.jar:/system/framework/wifi-service.jar', 'BOOTCLASSPATH': '/system/framework/core-libart.jar:/system/framework/conscrypt.jar:/system/framework/okhttp.jar:/system/framework/core-junit.jar:/system/framework/bouncycastle.jar:/system/framework/ext.jar:/system/framework/framework.jar:/system/framework/telephony-common.jar:/system/framework/voip-common.jar:/system/framework/ims-common.jar:/system/framework/mms-common.jar:/system/framework/android.policy.jar:/system/framework/apache-xml.jar:/system/framework/mediatek-common.jar:/system/framework/mediatek-framework.jar:/system/framework/mediatek-telephony-common.jar:/system/app/miui/miui.apk:/system/app/miuisystem/miuisystem.apk', 'ANDROID_PROPERTY_WORKSPACE': '8,0', 'PATH': '/sbin:/vendor/bin:/system/sbin:/system/bin:/system/xbin', 'ANDROID_STORAGE': '/storage', 'ANDROID_BOOTLOGO': '1', 'EMULATED_STORAGE_TARGET': '/storage/emulated', 'ANDROID_ASSETS': '/system/app', 'ANDROID_SOCKET_zygote_secondary': '9', 'PYTHONPATH': '/data/data/com.example.test/files/app:/data/data/com.example.test/files/app/lib', 'PYTHONOPTIMIZE': '2', 'ANDROID_PRIVATE': '/data/data/com.example.test/files', 'MC_AUTH_TOKEN_PATH': '/efs', 'USBOTG_STORAGE': '/storage/usbotg', 'ANDROID_ENTRYPOINT': 'main.pyo', 'SECONDARY_STORAGE': '/storage/sdcard1', 'ANDROID_UNPACK': '/data/data/com.example.test/files/app', 'ANDROID_DATA': '/data', 'EMULATED_STORAGE_SOURCE': '/mnt/shell/emulated', 'PYTHON_NAME': 'python', 'LD_PRELOAD': 'libsigchain.so:libudf.so', 'P4A_BOOTSTRAP': 'SDL2', 'ANDROID_ROOT': '/system', 'PYTHONHOME': '/data/data/com.example.test/files/app', 'ASEC_MOUNTPOINT': '/mnt/asec', 'ANDROID_ARGUMENT': '/data/data/com.example.test/files/app'})
I/python  (22541): ('Android kivy bootstrap done. __name__ is', '__main__')
I/python  (22541): ['/data/data/com.example.test/files/app/lib/python2.7/site-packages', '/data/data/com.example.test/files/app/lib/site-python']
I/python  (22541): AND: Ran string
I/python  (22541): Run user program, change dir and execute entrypoint
I/python  (22541): main.py
I/python  (22541): [WARNING] [Config      ] Older configuration version detected (0 instead of 20)
I/python  (22541): [WARNING] [Config      ] Upgrading configuration in progress.
I/python  (22541): [INFO   ] [Logger      ] Record log in /data/data/com.example.test/files/app/.kivy/logs/kivy_19-01-12_0.txt
I/python  (22541): [INFO   ] [Kivy        ] v1.10.1
I/python  (22541): [INFO   ] [Python      ] v2.7.15 (default, Jan 11 2019, 21:35:32) 
I/python  (22541): [GCC 4.2.1 Compatible Android (4691093 based on r316199) Clang 6.0.2 (https://a
I/python  (22541): [INFO   ] [Factory     ] 194 symbols loaded
I/python  (22541): [INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
I/python  (22541): [INFO   ] [Window      ] Provider: sdl2
I/python  (22541): [INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
I/python  (22541): [INFO   ] [GL          ] Backend used <gl>
I/python  (22541): [INFO   ] [GL          ] OpenGL version <OpenGL ES 3.1 build 1.4@3300288>
I/python  (22541): [INFO   ] [GL          ] OpenGL vendor <Imagination Technologies>
I/python  (22541): [INFO   ] [GL          ] OpenGL renderer <PowerVR Rogue G6200>
I/python  (22541): [INFO   ] [GL          ] OpenGL parsed version: 3, 1
I/python  (22541): [INFO   ] [GL          ] Texture max size <8192>
I/python  (22541): [INFO   ] [GL          ] Texture max units <16>
I/python  (22541): [INFO   ] [Window      ] auto add sdl2 input provider
I/python  (22541): [INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
I/python  (22541): [WARNING] [Base        ] Unknown <android> provider
I/python  (22541): [INFO   ] [Base        ] Start application main loop
I/python  (22541): [INFO   ] [GL          ] NPOT texture support is available
I/python  (22541): [INFO   ] [Text        ] Provider: sdl2
I/python  (22541): [WARNING] [Accordion   ] not enough space for displaying all children
I/python  (22541): [WARNING] [Accordion   ] need 264px, got 0px
I/python  (22541): [WARNING] [Accordion   ] layout aborted.
I/python  (22541): [INFO   ] [Loader      ] using a thread pool of 2 workers
I/python  (22541): [ERROR  ] [Loader      ] Failed to load image <https://paste.opensuse.org/images/97979538.jpg>
I/python  (22541): Traceback (most recent call last):
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/loader.py", line 317, in _load_urllib
I/python  (22541):     fd = urllib_request.urlopen(filename)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 154, in urlopen
I/python  (22541):     return opener.open(url, data, timeout)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 429, in open
I/python  (22541):     response = self._open(req, data)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 447, in _open
I/python  (22541):     '_open', req)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 407, in _call_chain
I/python  (22541):     result = func(*args)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 1241, in https_open
I/python  (22541):     context=self._context)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 1198, in do_open
I/python  (22541):     raise URLError(err)
I/python  (22541): URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)>
I/python  (22541): [ERROR  ] [Loader      ] Failed to load image <https://kushaldas.in/images/pyconin15-3.jpg>
I/python  (22541): Traceback (most recent call last):
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/loader.py", line 317, in _load_urllib
I/python  (22541):     fd = urllib_request.urlopen(filename)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 154, in urlopen
I/python  (22541):     return opener.open(url, data, timeout)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 429, in open
I/python  (22541):     response = self._open(req, data)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 447, in _open
I/python  (22541):     '_open', req)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 407, in _call_chain
I/python  (22541):     result = func(*args)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 1241, in https_open
I/python  (22541):     context=self._context)
I/python  (22541):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 1198, in do_open
I/python  (22541):     raise URLError(err)
I/python  (22541): URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)>

@homdx
Copy link

homdx commented Jan 11, 2019

Try it now please @homdx, it should work

Note: sorry, I didn't consider the @Jonast's application p4aspaces, my master branch was outdated...I only considered the merge conflicts...

@opacam First you merge and this pull request #1217
are missing you previous pull request?
#1568

@opacam
Copy link
Member

opacam commented Jan 11, 2019

yes

@homdx
Copy link

homdx commented Jan 11, 2019

From my log (adb):
ssl error: URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:726)>
for url https://paste.opensuse.org/images/97979538.jpg
I check in browser: (CN) Let's Encrypt Authority X3
(O) Let's Encrypt

Maybe request module don't know about let's encrypt certs??

@opacam
Copy link
Member

opacam commented Jan 11, 2019

About ssl certificate... that is another problem...I monkey patch my applications like this:

# Monkey patch to ssl certificate verification error
try:
    import ssl
    from functools import wraps

    print(('APPLYING MONKEY PATCH TO FORCE SSL '
          'PROTOCOL V1 [SSL VERSION: {}]'.format(
        ssl.OPENSSL_VERSION)))

    def sslwrap(func):
        @wraps(func)
        def bar(*args, **kw):
            kw['ssl_version'] = ssl.PROTOCOL_TLSv1
            return func(*args, **kw)
        return bar

    # This line below is to avoid error (detected in python-2.7.12 in linux platform):
    # URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)>
    # NOTE: This error causes that the tvshow's poster not to be shown/download when trying to load with kivy loader
    ssl._create_default_https_context = ssl._create_unverified_context

    ssl.wrap_socket = sslwrap(ssl.wrap_socket)
except Exception as e:
    print(('ERROR ON MONKEY PATCH SSL PROTOCOL V1: {}'.format(e)))

This has been working for me...probably it works for you...

@homdx
Copy link

homdx commented Jan 11, 2019

@opacam and where to add this code?
https://github.com/homdx/pydelhi_mobile

@opacam
Copy link
Member

opacam commented Jan 11, 2019

This should be run before any call to ssl...in you app source code...I would put somewhere before kivy loads your app (you can remove some comments I put in there and adapt to your code)

Also I would recommend you to see the following link, so you know what are you doing: https://en.wikipedia.org/wiki/Monkey_patch

😉

@homdx
Copy link

homdx commented Jan 11, 2019

@opacam funny patch name
Thanks. It's works!

I/python  (28202):   File "/data/data/com.example.test/files/app/_python_bundle/site-packages/kivy/loader.py", line 317, in _load_urllib
I/python  (28202):     fd = urllib_request.urlopen(filename)
I/python  (28202):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 154, in urlopen
I/python  (28202):     return opener.open(url, data, timeout)
I/python  (28202):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 435, in open
I/python  (28202):     response = meth(req, response)
I/python  (28202):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 548, in http_response
I/python  (28202):     'http', request, response, code, msg, hdrs)
I/python  (28202):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 473, in error
I/python  (28202):     return self._call_chain(*args)
I/python  (28202):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 407, in _call_chain
I/python  (28202):     result = func(*args)
I/python  (28202):   File "/data/data/com.example.test/files/app/_python_bundle/stdlib.zip/urllib2.py", line 556, in http_error_default
I/python  (28202):     raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
I/python  (28202): HTTPError: HTTP Error 404: Not Found

@ghost
Copy link

ghost commented Jan 11, 2019

I'm pretty sure TLS below 1.1 is considered somewhat insecure, so please note that this might not be such a good idea if you want it to be properly encrypted.

Did you try shipping your own cert storage and setting it? That might also work (it worked for me)

@homdx
Copy link

homdx commented Jan 11, 2019

I'm pretty sure TLS below 1.1 is considered somewhat insecure, so please note that this might not be such a good idea if you want it to be properly encrypted.

Did you try shipping your own cert storage and setting it? That might also work (it worked for me)

Tell me please. how is it done

@ghost
Copy link

ghost commented Jan 13, 2019

@homdx check https://docs.python.org/3/library/ssl.html for load_verify_locations

@AndreMiras maybe it would make sense to close this pull request as well?

@agilewalker thanks so much for your work, it was very helpful as intermediate solution but we got openssl/TLS workiing on p4a master right now!

@homdx
Copy link

homdx commented Jan 13, 2019

Notice: Flask with kivy in one app also are working!)) under ANDROIDAP=28 ANDROIDNDKVER=r17c NDKAPI=21 and Python3
Tkanks @opacam @Jonast @AndreMiras @agilewalker

@tshirtman tshirtman closed this Jan 13, 2019
if not os.path.exists(join(ndk_sources_python_dir, '3.6')):
os.mkdir(join(ndk_sources_python_dir, '3.6'))
sh.sed('s#3.5#3.6#',
join(ndk_sources_python_dir, '3.5/Android.mk'),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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

Successfully merging this pull request may close these issues.