OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
I was developing a Flask app. And it ran without any problems. Then I had a short break, no changes to the app. Meanwhile my subscription ended, and I renewed it. Today I tried to run the same app and received the message below. At the same time I am able to run this app from the windows 10 command line without any problem. I tried to change the default port, restart the PC, turn off windows Firewall - nothing helps. Any ideas. Thank you
FLASK_APP = RealecDB/database/RealecDB.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder F:/UserMike/Documents/PycharmProjects/RealecDB
F:\UserMike\Documents\PycharmProjects\RealecDB\venv\Scripts\python.exe -m flask run
* Serving Flask app "RealecDB/database/RealecDB.py"
* Environment: development
* Debug mode: off
Traceback (most recent call last):
File "C:\Users\Mike\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Mike\AppData\Local\Programs\Python\Python36-32\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\flask\__main__.py", line 15, in <module>
main(as_module=True)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\flask\cli.py", line 966, in main
cli.main(prog_name="python -m flask" if as_module else None)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\flask\cli.py", line 586, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\click\core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\flask\cli.py", line 860, in run_command
extra_files=extra_files,
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\werkzeug\serving.py", line 1010, in run_simple
inner()
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\werkzeug\serving.py", line 963, in inner
fd=fd,
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\werkzeug\serving.py", line 806, in make_server
host, port, app, request_handler, passthrough_errors, ssl_context, fd=fd
File "F:\UserMike\Documents\PycharmProjects\RealecDB\venv\lib\site-packages\werkzeug\serving.py", line 699, in __init__
HTTPServer.__init__(self, server_address, handler)
File "C:\Users\Mike\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 453, in __init__
self.server_bind()
File "C:\Users\Mike\AppData\Local\Programs\Python\Python36-32\lib\http\server.py", line 136, in server_bind
socketserver.TCPServer.server_bind(self)
File "C:\Users\Mike\AppData\Local\Programs\Python\Python36-32\lib\socketserver.py", line 467, in server_bind
self.socket.bind(self.server_address)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
Please sign in to leave a comment.
Do you use antivirus with on-access protection? If yes, try disabling it.
Check similar thread https://stackoverflow.com/questions/2778840/socket-error-errno-10013-an-attempt-was-made-to-access-a-socket-in-a-way-forb
It runs without a problem outside PyCharm! (From windows command line). I suspect antivirus covers command line as well.
If I'm not mistaken some antiviruses with on-access scan make exceptions for the default system applications.
How does it go if you run it from the embedded terminal in PyCharm? Does it give you the same error?
Yes, the same error. And I use windows antivirus only, and turning it off did not solve the problem.
I had this same issue. Here's how I fixed it:
Open CMD as administrator.
Run netstat -ano | find ":<port>"
This will show you a list of the processes using that port.
You can then run TASKKILL /F /PID <process id>. The process id is the far right column from the previous command.
Hope this helps
Does anyone have a solution to this please? I get the same, pick a port that's not in use, run it from command line and flask starts fine. Do the same within Pycharm IDE (Shift + F10) and I get