Search code examples
pythonpython-3.xlinuxpyusb

Open and read txt file from USB


I'm using Linux. I know my USB name is:

Bus 001 Device 005: ID 8564:1000 Transcend Information, Inc. JetFlash

and the idVendor and idProduct is:

idVendor           0x8564 Transcend Information, Inc.   
idProduct          0x1000 JetFlash

Where is the problem? Code or other stuff missing?

I read over the PyUSB: reading from a USB device (2), and other scenario but not really same as mine so give a hand pls.

import usb.core
import usb.util

dev = usb.core.find(idVendor= 0x8564, idProduct=0x1000)

ep = dev[0].interfaces()[0].endpoints()[0]
i=dev[0].interfaces()[0].bInterfaceNumber
dev.reset()

if dev.is_kernel_driver_active(i):
    print("hello")

The output from linux command (usb.core.USBError: [Errno 13] Access denied):

the output from linux command (usb.core.USBError: [Errno 13] Access denied )

  • tried with 'sudo python The_one_i_want.py'

tried with sudo python The_one_i_want.py

the output is

sudo: python:找不到指令
sudo: python: command not found

I just checked my sudo is working:
sudo is working

the output after I tried , sudo python The_one_i_want.pynow the output shows

python: can't open file '/home/joy/fe_dir/The_one_i_want.py': [Errno 2] No such file or directory can't open file

but file The_one_I_want (new).py The_one_I_want.py is inside /fe_dir directory tough

updated tried: now is 'ModuleNotFoundError: No module named 'usb'' , how to solved from here?
ModuleNotFoundError: No module named 'usb'


Solution

  • Simply run with sudo

    sudo python The_one_i_want.py
    

    Because the error you got says that you don't have permission to do that.