I would not recommend using urllib, instead, use
Python Requests. This module will make your life easier.
A realm can be thought of as an environment where multiple (or one) URL(s) are protected by a password. When your browser makes a HTTP request, asking the server for some HTML, the server may respond with "you need a password for this realm" or more simply "you need a password to receive this HTML".
In addition, the same server HTTP response will also contain what kind of authentication scheme to use. There is one called Basic, there is one called Digest. Whatever the server tells you to use, you
should use.
What I have described above is communicated via HTTP response headers. You should look up how a HTTP request and how a HTTP response looks like when it goes over the wire. This will help you in understanding how to communicate with a webserver.
As for the difference between the 2 authentication schemes: Basic auth is a password, unencrypted with base64 encoding while Digest does some encryption stuff involving a nonce.
Python requests can deal with both (and urllib for that matter).