Book Image

Python Essentials

By : Steven F. Lott
Book Image

Python Essentials

By: Steven F. Lott

Overview of this book

Table of Contents (22 chapters)
Python Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Web services and Internet protocols


As we noted earlier, many TCP/IP protocols, like HTTP, depend on the socket abstraction. Sockets are designed to be file-like: we can use ordinary file operations to read or write a socket. At a very low level, we can use the Python socket module. We can create, read, and write sockets to connect client and server programs.

Rather than work directly with sockets, however, we'll make use of higher-level modules, such as urllib and http.client. These give us the client-side operations of the HTTP protocol, allowing us to connect to a web server, make requests, and get replies. We looked briefly at the http.client module in the previous Closing file-like objects with contextlib section.

To implement a server, we can use http.server. In practice, though, we'll often leverage a frontend application, such as Apache HTTPD or NGINX, to provide the static content of a website. For the dynamic content, we'll often use a WSGI gateway to pass web requests from the frontend...