Cannot bind 127.0.0.123 to tcp socket python
On a Mac the loopback interface only has the 127.0.0.1 address configured. You could always add an alias to the IP you need:

sudo ifconfig lo0 alias 127.0.0.123


Your python code worked for me then.

To delete the alias do the following:

sudo ifconfig lo0 -alias 127.0.0.123




To make this persistent over reboots create org.local.localhost.plist in /Library/LaunchDaemons/. 
Change the permissions with: 

sudo chmod root:wheel /Library/LaunchDaemons/org.local.localhost.plist


Open the file with 

sudo nano /Library/LaunchDaemons/org.local.localhost.plist


and add the following content:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;org.local.localhost&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/sbin/ifconfig&lt;/string&gt;
        &lt;string&gt;lo0&lt;/string&gt;
        &lt;string&gt;alias&lt;/string&gt;
        &lt;string&gt;127.0.0.123&lt;/string&gt;
        &lt;string&gt;up&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
&lt;/dict&gt;
&lt;/plist&gt;


Finally load the launch daemon with:

sudo launchctl load /Library/LaunchDaemons/org.local.localhost.plist