Problem

When trying to bind the socket on a port that is not being occupied, the following permission error occurs:

ERROR:    [Errno 13] error while attempting to bind on address ('127.0.0.1', 80): アクセス許可で禁じられた方法でソケットにアクセスしようとしました。
ERROR:    [Errno 13] error while attempting to bind on address ('127.0.0.1', 80): attempt to access a socket not permitted by its access permissions

Solution

Method

  • Seems like it is because Hyper-V reserves some random port ranges, need to restart WinNAT service to make Hyper-V re-select the ports randomly.

Code

net stop winnat  
net start winnat

Additional Notes


References

How to Solve “Cannot Bind to Port Due to Permission Denied” on Windows

Stackoverflow: Cannot bind to some ports due to permission denied