Android上的Kivy:urlopen错误[Errno 4]名称解析中无法恢复的失败

时间:2016-05-12 21:53:14

标签: android python kivy

这个Kivy程序可以在我的Windows计算机上运行,​​但不是在我用buildozer打包并在Android上运行时。在Android上它给出错误:

I/python  ( 2173): <urlopen error [Errno 4] non-recoverable failure in name resolution.>

以下是该计划:

from kivy.app import App
from kivy.uix.label import Label
import json

try:
    # For Python 3.x
    from urllib.request import urlopen
except ImportError:
    # Fall back to Python 2's urllib2
    from urllib2 import urlopen

SETTINGS_URL = ('https://raw.githubusercontent.com/'
                'SpotterRF/jekyll-updater/master/package.json')


class MyApp(App):

    def build(self):
        response = urlopen(SETTINGS_URL)
        file_bytes = response.read()
        file_string = file_bytes.decode('utf-8')
        settings_dict = json.loads(file_string)

        return Label(text=settings_dict["name"])


MyApp().run()

buildozer.specrequirements = fysom, uuid, dropbox, six, kivy, pytz, requests

完整的adb日志:

I/python  ( 2173): ['/data/data/org.test.lanki/files/lib/python2.7/site-packages', '/data/data/org.test.lanki/files/lib/site-python']

I/python  ( 2173): Android path ['/data/data/org.test.lanki/files/lib/python27.zip', '/data/data/org.test.lanki/files/lib/python2.7', '/data/data/org.test.lanki/files/lib/python2.7/lib-dynload', '/data/data/org.test.lanki/files/lib/python2.7/site-packages', '/data/data/org.test.lanki/files', '/data/data/org.test.lanki/files/_applibs']

I/python  ( 2173): Android kivy bootstrap done. __name__ is __main__

I/python  ( 2173): Run user program, change dir and execute main.py

I/python  ( 2173): [INFO              ] [Logger      ] Record log in /data/data/org.test.lanki/files/.kivy/logs/kivy_16-05-12_3.txt

I/python  ( 2173): [INFO              ] [Kivy        ] v1.9.0

I/python  ( 2173): [INFO              ] [Python      ] v2.7.2 (default, May 12 2016, 21:42:08) 

I/python  ( 2173): [GCC 4.8]

D/StatusBar.NetworkController( 1213): onSignalStrengthsChanged signalStrength=SignalStrength: 99 99 -120 -160 -120 -1 -1 22 -101 -9 166 -1 2147483647 0x3000 gsm|lte level=3

D/StatusBar.NetworkController( 1213): updateTelephonySignalStrength: hasService=true ss=SignalStrength: 99 99 -120 -160 -120 -1 -1 22 -101 -9 166 -1 2147483647 0x3000 gsm|lte

D/StatusBar.NetworkController( 1213): updateTelephonySignalStrength: iconLevel=3

D/StatusBar.NetworkController( 1213): updateTelephonySignalStrength, No signal level. mPhoneSignalIconId = com.android.systemui:drawable/stat_sys_signal_3_auto_rotate mDataSignalIconId = com.android.systemui:drawable/stat_sys_signal_3_auto_rotate mQSPhoneSignalIconId = com.android.systemui:drawable/ic_qs_signal_3 mContentDescriptionPhoneSignal = Trois barres de signaux téléphoniques

D/HeadsetPhoneState( 3820): Signal level : previous=3 curr=3

D/CustomFrequencyManagerService(  980): releaseDVFSLockLocked : Getting Lock type frm List : DVFS_MIN_LIMIT  frequency : 1958400  uid : 1000  pid : 980  tag : ACTIVITY_RESUME_BOOSTER@15

D/CustomFrequencyManagerService(  980): FrequencyrequestList.getNextCStateDisableRequest, index: 5

I/python  ( 2173): [INFO              ] [Factory     ] 173 symbols loaded

D/StatusBar.NetworkController( 1213): refreshViews connected={ wifi } level=3 combinedSignalIconId=0x7f0205d9/com.android.systemui:drawable/stat_sys_wifi_signal_4 mobileLabel=Bell wifiLabel="Mawer" emergencyOnly=false combinedLabel="Mawer" mAirplaneMode=false mDataActivity=0 mPhoneSignalIconId=0x7f02052e/com.android.systemui:drawable/stat_sys_signal_3_auto_rotate mQSPhoneSignalIconId=0x7f020154/com.android.systemui:drawable/ic_qs_signal_3 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f02052e/com.android.systemui:drawable/stat_sys_signal_3_auto_rotate mDataTypeIconId=0x7f0203b8/com.android.systemui:drawable/stat_sys_data_connected_lte mQSDataTypeIconId=0x7f020157/com.android.systemui:drawable/ic_qs_signal_4g mNoSimIconId=0x0/(null) mWifiIconId=0x7f0205d9/com.android.systemui:drawable/stat_sys_wifi_signal_4 mQSWifiIconId=0x7f0202c7/com.android.systemui:drawable/qs_tile_wifi_signal_4 mWifiActivityIconId=0x7f020590/com.android.systemui:drawable/stat_sys_signal_no_inout mBluetoothTetherIconId=0x7f0205b6/com.android.systemui:drawable/stat_sys_tether_bluetooth

D/StatusBar.NetworkController( 1213): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

D/StatusBar.NetworkController( 1213): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

D/StatusBar.NetworkController( 1213): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

D/StatusBar.NetworkController( 1213): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

D/StatusBar.NetworkController( 1213): refreshViews connected={ wifi } level=3 combinedSignalIconId=0x7f0205d9/com.android.systemui:drawable/stat_sys_wifi_signal_4 mobileLabel=Bell wifiLabel="Mawer" emergencyOnly=false combinedLabel="Mawer" mAirplaneMode=false mDataActivity=0 mPhoneSignalIconId=0x7f02052e/com.android.systemui:drawable/stat_sys_signal_3_auto_rotate mQSPhoneSignalIconId=0x7f020154/com.android.systemui:drawable/ic_qs_signal_3 mDataDirectionIconId=0x0/(null) mDataSignalIconId=0x7f02052e/com.android.systemui:drawable/stat_sys_signal_3_auto_rotate mDataTypeIconId=0x7f0203b8/com.android.systemui:drawable/stat_sys_data_connected_lte mQSDataTypeIconId=0x7f020157/com.android.systemui:drawable/ic_qs_signal_4g mNoSimIconId=0x0/(null) mWifiIconId=0x7f0205d9/com.android.systemui:drawable/stat_sys_wifi_signal_4 mQSWifiIconId=0x7f0202c7/com.android.systemui:drawable/qs_tile_wifi_signal_4 mWifiActivityIconId=0x7f02058b/com.android.systemui:drawable/stat_sys_signal_in mBluetoothTetherIconId=0x7f0205b6/com.android.systemui:drawable/stat_sys_tether_bluetooth

D/StatusBar.NetworkController( 1213): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

D/StatusBar.NetworkController( 1213): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

D/StatusBar.NetworkController( 1213): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

D/StatusBar.NetworkController( 1213): refreshNwBoosterIndicator - setNWBoosterIndicators(false)

I/python  ( 2173):  /data/data/org.test.lanki/files/lib/python2.7/site-packages/kivy/core/image/img_pygame.py:13: RuntimeWarning: import cdrom: No module named cdrom

I/python  ( 2173):  (ImportError: No module named cdrom)

I/python  ( 2173): [INFO              ] [Image       ] Providers: img_tex, img_dds, img_gif, img_pygame (img_pil, img_ffpyplayer ignored)

I/python  ( 2173): [INFO              ] [Text        ] Provider: pygame

I/python  ( 2173): URL Error: Could not download settings json files.

I/python  ( 2173): <urlopen error [Errno 4] non-recoverable failure in name resolution.>

I/WindowState(  980): WIN DEATH: Window{a154366 u0 d0 SurfaceView}

I/SurfaceFlinger(  257): id=2635 Removed TurfaceView (5/8)

W/InputDispatcher(  980): channel ~ Consumer closed input channel or an error occurred.  events=0x9

E/InputDispatcher(  980): channel ~ Channel is unrecoverably broken and will be disposed!

I/SurfaceFlinger(  257): id=2635 Removed TurfaceView (-2/8)

I/ActivityManager(  980): Process org.test.lanki:python (pid 2173)(adj 0) has died(104,346)

D/ActivityManager(  980): isAutoRunBlockedApp:: org.test.lanki, Auto Run ON

W/ActivityManager(  980): Force removing ActivityRecord{cdfb7ad u0 org.test.lanki/org.renpy.android.PythonActivity t14123}: app died, no saved state

D/FocusedStackFrame(  980): Set to : 0

I/WindowState(  980): WIN DEATH: Window{319fb08e u0 d0 org.test.lanki/org.renpy.android.PythonActivity}

1 个答案:

答案 0 :(得分:1)

正如@JustMe和@inclement在评论中指出的那样,答案是修改buildozer.spec所以存在以下两行:

  • android.permissions = INTERNET

  • openssl已添加到requirements行;在我的情况下它变成:
    requirements = fysom, uuid, dropbox, six, kivy, pytz, requests, openssl