Close HTTPResponse Objects
00:00
The HTTPResponse
object has a lot in common with the file object. The HTTPResponse
class inherits from the IOBase
class, as do file objects, which means that you have to be mindful of opening and closing.
00:13
In simple programs, you’re not likely to notice any issues if you forget to close HTTPResponse
objects.
00:19
For more complex projects, this can significantly slow execution and cause bugs that are difficult to pinpoint. Problems arise because input/output streams are limited; each HTTPResponse
requires a stream to be kept clear while it’s being read.
00:36 If you never close your streams, this will eventually prevent any other stream from being opened, and it might interfere with other programs or even your operating system.
00:44
So make sure you’ve closed your HTTPResponse
objects. For your convenience, you can use a context manager, as you’ve seen in examples.
00:54 Next lesson, you’ll learn how to go from bytes to strings.
Become a Member to join the conversation.