Kivy:AsyncImage和Urllib不会在Android上打开任何网址

时间:2017-11-07 21:55:52

标签: android python kivy

我最近开始使用我已经在我的电脑上用kivy编写的一些程序来定位android,但是在我的手机上构建和安装之后我发现urllib似乎不接受任何网址,尽管事实是它在我的电脑上完美运行。另外,任何使用urllib连接到互联网的kivy小部件都会以完全相同的方式失败。

以下是一些示例代码:

from kivy.app import App
from kivy.uix.image import AsyncImage

class TestApp(App):
    def build(self):
        return AsyncImage(source="http://kivy.org/logos/kivy-logo-black-64.png")

TestApp().run()

当应用程序运行时,它会出现在logcat:

11-07 15:50:10.400  3741  4686 I python  : [INFO   ] [GL          ] 
Using the "OpenGL ES 2" graphics system
11-07 15:50:10.400  3741  4686 I python  : [INFO   ] [GL          ] 
Backend used <gl>
11-07 15:50:10.410  3741  4686 I python  : [INFO   ] [GL          ] 
OpenGL version <b'OpenGL ES 3.1 V@140.0 (GIT@Ifd751822f5)'>
11-07 15:50:10.410  3741  4686 I python  : [INFO   ] [GL          ] 
OpenGL vendor <b'Qualcomm'>
11-07 15:50:10.410  3741  4686 I python  : [INFO   ] [GL          ] 
OpenGL renderer <b'Adreno (TM) 420'>
11-07 15:50:10.410  3741  4686 I python  : [INFO   ] [GL          ] 
OpenGL parsed version: 3, 1
11-07 15:50:10.410  3741  4686 I python  : [INFO   ] [GL          ] 
Texture max size <16384>
11-07 15:50:10.410  3741  4686 I python  : [INFO   ] [GL          ] 
Texture max units <16>
11-07 15:50:10.470  3741  4686 I python  : [INFO   ] [Window      ] 
auto add sdl2 input provider
11-07 15:50:10.470  3741  4686 I python  : [INFO   ] [Window      ] 
virtual keyboard not allowed, single mode, not docked
11-07 15:50:10.550  3741  4686 I python  : [INFO   ] [Loader      ] 
using a thread pool of 2 workers
11-07 15:50:10.720  3741  4686 I python  : [WARNING] [Base        ] 
Unknown <android> provider
11-07 15:50:10.720  3741  4686 I python  : [INFO   ] [Base        ] Start application main loop
11-07 15:50:10.740  3741  4686 I python  : [ERROR  ] [Base        ] Failed to import "android" module. Could not remove android presplash.
11-07 15:50:12.130  3741  4943 I python  : [ERROR  ] [Loader      ] Failed to load image <http://kivy.org/logos/kivy-logo-black-64.png>
11-07 15:50:12.130  3741  4943 I python  : Traceback (most recent call last):
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/site-packages/kivy/loader.py", line 317, in _load_urllib
11-07 15:50:12.130  3741  4943 I python  :     fd = urllib_request.urlopen(filename)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 162, in urlopen
11-07 15:50:12.130  3741  4943 I python  :     return opener.open(url, data, timeout)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 471, in open
11-07 15:50:12.130  3741  4943 I python  :     response = meth(req, response)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 581, in http_response
11-07 15:50:12.130  3741  4943 I python  :     'http', request, response, code, msg, hdrs)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 503, in error
11-07 15:50:12.130  3741  4943 I python  :     result = self._call_chain(*args)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 443, in _call_chain
11-07 15:50:12.130  3741  4943 I python  :     result = func(*args)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 686, in http_error_302
11-07 15:50:12.130  3741  4943 I python  :     return self.parent.open(new, timeout=req.timeout)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 465, in open
11-07 15:50:12.130  3741  4943 I python  :     response = self._open(req, data)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 488, in _open
11-07 15:50:12.130  3741  4943 I python  :     'unknown_open', req)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 443, in _call_chain
11-07 15:50:12.130  3741  4943 I python  :     result = func(*args)
11-07 15:50:12.130  3741  4943 I python  :   File "/data/user/0/org.lgt.lgt/files/app/crystax_python/stdlib.zip/urllib/request.py", line 1310, in unknown_open
11-07 15:50:12.130  3741  4943 I python  :     raise URLError('unknown url type: %s' % type)
11-07 15:50:12.130  3741  4943 I python  : urllib.error.URLError: <urlopen error unknown url type: https>

这对我来说是一个非常奇怪的错误,因为我提交的网址是http而不是https

这是我的buildozer规范文件 link

1 个答案:

答案 0 :(得分:0)

您尝试使用http://kivy.org/logos/kivy-logo-black-64.png协议在网址上加载(https)重定向的网址(只需将其加载到浏览器中即可查看)。

要在Android上加载https网址,您应该使用OpenSSL支持构建您的apk。

在Python 2上,可以通过在buildozer的要求中添加openssl来实现。

我不确定它是否适用于python3crystax