[WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

Answered

 Evaluating PyCharm. Created my first Flask application using the site tutorial. When attempting to run getting exception:

[WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions.

Providing full stack:

FLASK_APP = app.py
FLASK_ENV = development
FLASK_DEBUG = 0
In folder C:/Users/ykasan/PycharmProjects/PyCharmFlask
C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\Scripts\python.exe -m flask run
* Serving Flask app "app.py"
* Environment: development
* Debug mode: off
Traceback (most recent call last):
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\flask\__main__.py", line 14, in <module>
main(as_module=True)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\flask\cli.py", line 894, in main
cli.main(args=args, prog_name=name)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\flask\cli.py", line 557, in main
return super(FlaskGroup, self).main(*args, **kwargs)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\click\core.py", line 717, in main
rv = self.invoke(ctx)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\click\core.py", line 1137, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\click\core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\click\decorators.py", line 64, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\click\core.py", line 555, in invoke
return callback(*args, **kwargs)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\flask\cli.py", line 771, in run_command
threaded=with_threads, ssl_context=cert)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\werkzeug\serving.py", line 814, in run_simple
inner()
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\werkzeug\serving.py", line 774, in inner
fd=fd)
File "C:\Users\ykasan\PycharmProjects\PyCharmFlask\venv\lib\site-packages\werkzeug\serving.py", line 660, in make_server
passthrough_errors, ssl_context, fd=fd)
File "C:\Users\XXXX\PycharmProjects\PyCharmFlask\venv\lib\site-packages\werkzeug\serving.py", line 577, in __init__
self.address_family), handler)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\socketserver.py", line 453, in __init__
self.server_bind()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\http\server.py", line 136, in server_bind
socketserver.TCPServer.server_bind(self)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\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

Process finished with exit code 1

 

Please advice.

 

6 comments

Hi Ykasan,

This looks like a firewall issue. Did you update your system, change any firewall settings or install any antivirus software that could block this? Could you double check this matter with software that could block network communications for the application, please?

0

Hello Sergey.

So, why Visual studio is running same code without any problems? Does not look like firewall issue to me.

Plus, the connection is  - localhost.

0

All the similar issues, as I can see, are related to firewall/antivirus or a network.

Try pausing firewall/antivirus, reboot the computer.

0

1. What server PyCharm uses ?

2. Is there a way to make it call IIS Express?

 

Thank you

0

I have the same issue. Tried to use flask-mail to send an email through a registration process and got this error. Any idea how to contain it in PyCharm?

 

Traceback (most recent call last):
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask_security\decorators.py", line 230, in wrapper
return f(*args, **kwargs)
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask_security\views.py", line 118, in register
user = register_user(**form.to_dict())
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask_security\registerable.py", line 41, in register_user
'welcome', user=user, confirmation_link=confirmation_link)
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask_security\utils.py", line 401, in send_mail
mail.send(msg)
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask_mail.py", line 491, in send
with self.connect() as connection:
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask_mail.py", line 144, in __enter__
self.host = self.configure_host()
File "C:\Users\developer\PycharmProjects\sendmessage\venv\lib\site-packages\flask_mail.py", line 158, in configure_host
host = smtplib.SMTP(self.mail.server, self.mail.port)
File "C:\Users\developer\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\developer\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\developer\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 306, in _get_socket
self.source_address)
File "C:\Users\developer\AppData\Local\Programs\Python\Python36\lib\socket.py", line 722, in create_connection
raise err
File "C:\Users\developer\AppData\Local\Programs\Python\Python36\lib\socket.py", line 713, in create_connection
sock.connect(sa)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
127.0.0.1 - - [06/Dec/2018 22:24:46] "POST /register HTTP/1.1" 500 -

0

Hi Afzalfarooqui,

Please try running it from the command line (outside of PyCharm) using the same interpreter. Do you have the same error?

0

Please sign in to leave a comment.