How Do You Write a Python Program to Simulate a Dial-by-Name directory?

Updated on 9/19/19 to use Python 3

Problem scenario
You have a list of first and last names in a file.  You want a program to extract the last names based on the first two or three letters.  You want to allow the user to dial by last name (to enter phone keys that correspond to letters of last names).  You want the user to enter a sequence of numbers that will correspond to the first two or three letters of the person’s last name. 

How Do You Install the Latest Version of python-setuptools (aka easy_install) when Your Package Repositories Do Not Have It Available?

Problem scenario
Your apt or yum repositories do not have the newest version of python-setuptools (aka easy_install) available.  You need to install a recent version.  What should you do?

Solution
Prerequisites
a.  You need to have unzip installed.  Debian/Ubuntu servers usually have this by default, but if you still need assistance, see the Debian/Ubuntu link below.  Click on your distribution of Linux for assistance with installing unzip:
CentOS/RHEL/Fedora
Debian/Ubuntu
SUSE
b. 

How Do You Use Python Eve as a RESTful Endpoint on an Ubuntu Server?

Problem scenario
You want to use Python Eve to test it out.  You also want to create a RESTful endpoint on an Ubuntu Linux server.  How do you do this?

Solution
1.  Install Eve on the Ubuntu server.  Here is one way:

sudo apt-get -y update
sudo apt-get -y install python python-pip
sudo pip install eve

An alternative way to install it is given 

How Do You Install python-snappy on an Ubuntu/Debian Linux Server?

Problem scenario
You are trying to install python-snappy on Ubuntu (or a Debian distribution of) Linux.  You go here and find no obvious dependencies or prerequisites:
https://pypi.python.org/pypi/python-snappy

But when you try to install it, you run “python setup.py build” and get an error like this:

“/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: ‘install_requires’
  warnings.warn(msg)
running build
running build_py
package init file ‘__init__.py’ not found (or not a regular file)
package init file ‘__init__.py’ not found (or not a regular file)
running build_ext
building ‘_snappy’ extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time – D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c 

How Do You Fix a Python Program That Returns an Error “…subprocess.py … in check_output”?

Problem scenario
You are trying to use subprocess and check_output in Python to run raw Bash/shell/Linux commands.  

Your Python program has a line like this:
subprocess.check_output(“/usr/local/bin/coolprog arg1 /path/to/file.txt arg3”)

You get this error when you run the program:

 File “/usr/lib/python2.7/subprocess.py”, line 566, in check_output

What do you do?

Solution
This solution only applies if the Bash command is constructed from known good input. 

How Do You Troubleshoot the Error “ERROR: S3 error: 400 (InvalidRequest): The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.”

Problem scenario
Some s3cmd commands work fine.  But others give you this error:
“ERROR: S3 error: 400 (InvalidRequest): The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.”

What can you do to get s3cmd commands to work consistently?

Solution
Upgrade your s3cmd to a newer version.