With the OS X firewall enabled, you can remove the "Do you want the application “Python.app” to accept incoming network connections?" message.

mac-os-x-do-you-want-the-application-python-app-to-accept-incoming-network-connections-01

Solution 1

You can simply select "Allow All" in your firewall, or simply turn it off.

Settings —> Security & Privacy  —>  Firewall   —>  Off

mac-os-x-do-you-want-the-application-python-app-to-accept-incoming-network-connections-00

 

Solution 2

Create a self-signed certificate.

  1. Open Keychain Access. Applications > Utilities > Keychain Access.
  2. Keychain Access menu > Certificate Assistant > Create a Certificate...
  3. Enter a Name like "Python-App-Cert".
  4. Select Identity Type: Self Signed Root
  5. Select Certificate Type: Code Signing
  6. Check the Let me override defaults box
  7. Click Continue,Enter a unique Serial Number,such as 1
  8. Enter 7300 for Validity Period. (gives you 20 years  365*20)
  9. Click Continue for the rest of the dialogs
  10. Email, Name, etc. fill out as you wish.    xxx@mimvp.com; Python-App-Cert; mimvp.com; ceo; beijing; beijing; CN
  11. Key pair info: set to RSA, 2048 bits. Does not really matter IMHO.
  12. From "Key Usage Extension" up to "Subject Alternate Name Extension": accept the defaults.
  13. Location: login keychain.
  14. Once it is created, set to "Always trust" in the Login keychain: right-click on the certificate, choose "Get Info",
  15. in the "Trust" section, set "When using this certificate" to "Always trust".

mac-os-x-do-you-want-the-application-python-app-to-accept-incoming-network-connections-02

mac-os-x-do-you-want-the-application-python-app-to-accept-incoming-network-connections-03

mac-os-x-do-you-want-the-application-python-app-to-accept-incoming-network-connections-05

 mac-os-x-do-you-want-the-application-python-app-to-accept-incoming-network-connections-06

mac-os-x-do-you-want-the-application-python-app-to-accept-incoming-network-connections-07

 

Now sign your application

sudo codesign -s <certname> -f --deep /path/to/application.app

sudo codesign -s "Python-App-Cert" -f /Library/Frameworks/Python.framework/Versions/2.7/bin/python

sudo codesign --force --deep --sign - /Library/Frameworks/Python.framework/Versions/2.7/bin/python

If that doesn't help, try without --deep and without the trailing slash:

sudo codesign --force --sign - /Library/Frameworks/Python.framework/Versions/2.7/bin/python

 

Note that when using a virtual environment,

you need to activate the virtual environment before running this command.

In the dialog that appears, click "Allow".