简体   繁体   中英

My permission is denied using Kivy

I'm trying to make an app with kivy but my permission is denied. I installed it the recommended way for xubuntu on the kivy website by adding the ppa and using sudo apt-get. When I run the app the GUI appears but when I press a button that should return some text, the gui closes and I get an error that my class 'MITMs1' does not have an attribute 'self'. I'm also using scapy and i'm on python 2.7.

here is a similar problem https://i11.at/dwl/eos/kivy30.pdf but my os error is

OSError: [Errno 13] Permission denied: '/dev/input/event5'

My full output is

[INFO   ] [Logger      ] Record log in /home/ro/.kivy/logs/kivy_15-12-27_25.txt
[INFO   ] [Kivy        ] v1.9.0
[INFO   ] [Python      ] v2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2]
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Factory     ] 173 symbols loaded
[INFO   ] [Text        ] Provider: sdl2
 WARNING: No route found for IPv6 destination :: (no default route?)
[INFO   ] [OSC         ] using <multiprocessing> for socket
[INFO   ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO   ] [GL          ] OpenGL version <3.0 Mesa 10.3.2>
[INFO   ] [GL          ] OpenGL vendor <Intel Open Source Technology Center>
[INFO   ] [GL          ] OpenGL renderer <Mesa DRI Intel(R) Bay Trail >
[INFO   ] [GL          ] OpenGL parsed version: 3, 0
[INFO   ] [GL          ] Shading version <1.30>
[INFO   ] [GL          ] Texture max size <8192>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event5
[INFO   ] [MTD         ] Read event from </dev/input/event5>
[INFO   ] [Base        ] Start application main loop
 Exception in thread Thread-1:
 Traceback (most recent call last):
   File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
     self.run()
   File "/usr/lib/python2.7/threading.py", line 763, in run
     self.__target(*self.__args, **self.__kwargs)
   File "/usr/lib/python2.7/dist-packages/kivy/input/providers/mtdev.py", line 197, in _thread_run
     _device = Device(_fn)
   File "/usr/lib/python2.7/dist-packages/kivy/lib/mtdev.py", line 131, in __init__
     self._fd = os.open(filename, os.O_NONBLOCK | os.O_RDONLY)
 OSError: [Errno 13] Permission denied: '/dev/input/event5'

[INFO   ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "skivy.py", line 76, in <module>
     MITMtool().run()
   File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 824, in run
     runTouchApp()
   File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 487, in runTouchApp
     EventLoop.window.mainloop()
   File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_sdl2.py", line 539, in mainloop
     self._mainloop()
   File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_sdl2.py", line 300, in _mainloop
     EventLoop.idle()
   File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 330, in idle
     self.dispatch_input()
   File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 315, in dispatch_input
     post_dispatch_input(*pop(0))
   File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 281, in post_dispatch_input
     wid.dispatch('on_touch_up', me)
   File "_event.pyx", line 699, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:6856)
   File "/usr/lib/python2.7/dist-packages/kivy/uix/behaviors.py", line 163, in on_touch_up
     self.dispatch('on_release')
   File "_event.pyx", line 695, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:6815)
   File "_event.pyx", line 1168, in kivy._event.EventObservers.dispatch (kivy/_event.c:11690)
   File "_event.pyx", line 1052, in kivy._event.EventObservers._dispatch (kivy/_event.c:10730)
   File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1465, in custom_callback
     exec(__kvlang__.co_value, idmap)
   File "<string>", line 23, in <module>
   File "skivy.py", line 64, in run_ifconfig
     + '[color=00ff00][i]{0}[/i][/color]'.format(self.ipv6) + '\n\n'
 AttributeError: 'MITMs1' object has no attribute 'self'

My code is

from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
from kivy.lang import Builder
from kivy.app import App
from scapy.all import *
from kivy.uix.scrollview import ScrollView
from kivy.uix.screenmanager import ScreenManager, Screen
from subprocess import check_output

Builder.load_string('''
<MITMs1>:
    BoxLayout:
        BoxLayout:
            orientation: 'vertical'
            id: client_box
            size_hint: 0.5, 1
            spacing: 10
            Label:
                id: device_lbl
                markup: True
                size_hint: 1, 1
                text: 'LABEL! :)'
            TextInput:
                id: iface_name
                size_hint: 1, .2
                text: 'eth0'
                multiline: False
            BoxLayout:
                Button:
                    size_hint: 1, .2
                    text: 'Run Ifconfig'
                    on_release: root.run_ifconfig()
        ScrollView:
            size_hint: 0.5, 1
            do_scroll_x: False
            BoxLayout:
                orientation: 'vertical'
                id: nodes
                size_hint: 1, None

            ''')

class MITMs1(Screen):
    def __init__(self, **kwargs):
        super(MITMs1, self).__init__(**kwargs)

        self.iface_name = self.ids['iface_name']
        self.device_lbl = self.ids['device_lbl']
        self.client_box = self.ids['client_box']
        self.nodes = self.ids['nodes']

    def run_ifconfig(self):

        self.ifconfig = subprocess.check_output(['ifconfig', self.iface_name.text])
        self.iface, self.my_ip, self.MAC, self.Bcast, self.Nmask, self.ipv6 = (self.ifconfig.split()[i] for i in (0, 6, 4, 7, 8, 11))
        self.device_lbl.text = ('[color=00ff00][i][b]My Device[/b][/i][/color]' + '\n\n' + 'Interface: '
        + '[color=00ff00][i]{0}[/i][/color]'.format(self.iface) + '\n\n' + 'IP: '
        + '[color=00ff00][i]{0}[/i][/color]'.format(self.my_ip[5:]) + '\n\n' + 'MAC: '
        + '[color=00ff00][i]{0}[/i][/color]'.format(self.self.MAC) + '\n\n' + 'Bcast: '
        + '[color=00ff00][i]{0}[/i][/color]'.format(self.Bcast[6:]) + '\n\n' + 'Nmask: '
        + '[color=00ff00][i]{0}[/i][/color]'.format(self.Nmask[5:]) + '\n\n' + 'IP: '
        + '[color=00ff00][i]{0}[/i][/color]'.format(self.ipv6) + '\n\n'
)


class MITMtool(App):
    def build(self):
        return sm

sm = ScreenManager()
sm.add_widget(MITMs1(name='MITMs1'))

if __name__=='__main__':
    MITMtool().run()

You have format(self.self.MAC) in the middle of the string construction. This is why you get the error about not having a self.self .

The input error isn't important, it just comes from kivy querying your input devices to see what's available.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM