urllib in Python

urllib is a package in Python programming that can be used working with the URLs.

urllib.request will be used for opening and reading URLs.

urllib.error will be containing the exceptions raised by urllib.request.

urllib.parse is used for parsing the URLs.

Syntax:

import urllib.request, urllib.parse, urllib.error

urllib can be used to make API Calls from Python Programming. It makes API Callouts easier. urllib.request.urlopen() can be used to do the API calls. We can parse the returned payload from the API Calls.

Sample Code:

import urllib.request, urllib.parse, urllib.error
objResponse = urllib.request.urlopen( 
    'http://www.thomas-bayer.com/sqlrest/CUSTOMER/1' 
);
for strResponse in objResponse:
    print(
        strResponse.strip()
    );

Leave a Reply