secure_with_urlopen
This example demonstrates how to use a custom global URL opener installed with urllib.request.install_opener to block access to URLs.
Classes:
-
SecuredHTTPHandler–A HTTP handler that blocks access to URLs that end with “blocked.jsonld”.
Functions:
-
main–The main code of the example.
SecuredHTTPHandler
Bases: HTTPHandler
A HTTP handler that blocks access to URLs that end with “blocked.jsonld”.
Methods:
-
http_open–Block access to URLs that end with “blocked.jsonld”.
http_open
http_open(req: Request) -> HTTPResponse
Block access to URLs that end with “blocked.jsonld”.
Parameters:
-
(reqRequest) –The request to open.
Returns:
-
HTTPResponse–The response.
Raises:
-
PermissionError–If the URL ends with “blocked.jsonld”.
Source code in examples/secure_with_urlopen.py
main
The main code of the example.
The important steps are:
- Install a custom global URL opener that blocks some URLs.
- Attempt to parse a JSON-LD document that will result in a blocked URL being accessed.
- Verify that the URL opener blocked access to the URL.