Book Image

Python Requests Essentials

By : Rakesh Vidya Chandra, Bala Subrahmanyam Varanasi
Book Image

Python Requests Essentials

By: Rakesh Vidya Chandra, Bala Subrahmanyam Varanasi

Overview of this book

<p>Python is one of the most popular programming languages of our era; the Python Requests library is one of the world's best clients, with the highest number of downloads. It allows hassle-free interactions with web applications using simple procedures.</p> <p>You will be shown how to mock HTTP Requests using HTTPretty, and will learn to interact with social media using Requests. This book will help you to grasp the art of web scraping with the BeautifulSoup and Python Requests libraries, and will then paddle you through Requests impressive ability to interact with APIs. It will empower you with the best practices for seamlessly drawing data from web apps. Last but not least, you will get the chance to polish your skills by implementing a RESTful Web API with Python and Flask!</p>
Table of Contents (15 chapters)
Python Requests Essentials
Credits
About the Authors
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Errors and exceptions


Different types of errors and exceptions will be raised when something goes wrong in the process of sending a request and getting back a response. Some of them are as follows:

  • HTTPError: When there are invalid HTTP responses, Requests will raise an HTTPError exception

  • ConnectionError: If there is a network problem, such as refused connection and DNS failure, Requests will raise a ConnectionError exception

  • Timeout: If the request gets timed out, this exception will be raised

  • TooManyRedirects: If the request surpasses the configured number of maximum redirections, this type of exception is raised

Other types of exception that come in to the picture are Missing schema Exception, InvalidURL, ChunkedEncodingError, and ContentDecodingError and so on.

This example has been taken from Request documents available at http://docs.python-requests.org/en/latest/user/quickstart/#errors-and-exceptions.