March 2019
Beginner
490 pages
12h 40m
English
Now, are going to create the same script but, instead of using urllib, we are going to use the requests module. For this, create a text file called RFC_download_requests.py:
#!/usr/bin/env python3import sys, requeststry: rfc_number = int(sys.argv[1])except (IndexError, ValueError): print('Must supply an RFC number as first argument') sys.exit(2)template = 'http://www.rfc-editor.org/rfc/rfc{}.txt'url = template.format(rfc_number)rfc = requests.get(url).textprint(rfc)
We can simplify the previous script using the requests module. The main difference with the requests module is that we use the get method for the request and access the text property to get information about the specific RFC.
Read now
Unlock full access