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

python3 api\index.py failed #29

Closed
Blaise-wig opened this issue Mar 12, 2024 · 5 comments
Closed

python3 api\index.py failed #29

Blaise-wig opened this issue Mar 12, 2024 · 5 comments

Comments

@Blaise-wig
Copy link

Hello, when I run python3 api\index.py, I get this error

(DroneControl) C:\Users\Victus\anaconda3\envs\DroneControl\Mocap-Drones-main\computer_code>python api\index.py

  • Serving Flask app 'index'
  • Debug mode: on
    WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
  • Running on http://127.0.0.1:3001
    Press CTRL+C to quit
  • Restarting with stat
    Traceback (most recent call last):
    File "C:\Users\Victus\anaconda3\envs\DroneControl\Mocap-Drones-main\computer_code\api\index.py", line 22, in
    ser = serial.Serial("COM12", 115200, write_timeout=1, )
    File "C:\Users\Victus\anaconda3\envs\DroneControl\lib\site-packages\serial\serialwin32.py", line 33, in init
    super(Serial, self).init(*args, **kwargs)
    File "C:\Users\Victus\anaconda3\envs\DroneControl\lib\site-packages\serial\serialutil.py", line 244, in init
    self.open()
    File "C:\Users\Victus\anaconda3\envs\DroneControl\lib\site-packages\serial\serialwin32.py", line 64, in open
    raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
    serial.serialutil.SerialException: could not open port 'COM12': PermissionError(13, 'Access is denied.', None, 5)

I connected the esp32 to COM12 and made sure no other program is using the port. I have been trying to resolve this for two days now. can anyone help?

@jyjblrd
Copy link
Owner

jyjblrd commented Mar 12, 2024

PermissionError(13, 'Access is denied.', None, 5)

Have you tried running with sudo? ie. sudo python3 api\index.py

@jyjblrd
Copy link
Owner

jyjblrd commented Mar 12, 2024

Also make sure that your arduino ide / whatever you are using to program the ESP32 is closed, because it could also be connecting to the port.

@Blaise-wig
Copy link
Author

I'm on windows. But I ran it as administrator. I also closed the arduino IDE but the error still persisted.

@clennpillo
Copy link

weird windows permission problem, I gave up windows and tried WSL, it worked.

@clennpillo
Copy link

clennpillo commented Jun 8, 2024

I was lately trying to run the code on windows10, and solved this permission problem, here is the detail.

if you are quite sure you serial port is not occupied by another program which is the situation in my case, but you still ran into the weird permissionerror 13 problem, you may try these steps.

first, turn off the reloader function of Flask-SocketIO, as flask-socketio might use your serial port which caused the permission problem.

second, create a unique thread for pyserial to operate serial port.

here is the code i use

app = Flask(__name__)
socketio = SocketIO(app, cors_allowed_origins='*', async_mode='threading')

serial_lock = threading.Lock()
ser = None

def serial_worker():
    global ser
    try:
        with serial_lock:
            ser = serial.Serial("COM5", 1000000, write_timeout=1)
    except Exception as e:
        print(f"Serial exception: {e}")
if __name__ == '__main__':

    serial_thread = threading.Thread(target=serial_worker)
    serial_thread.daemon = True 
    serial_thread.start()

    socketio.run(app, port=3001, debug=True, use_reloader=False)

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

No branches or pull requests

3 participants