class NoOpHandler(urllib.request.HTTPRedirectHandler):

    def redirect_request(self, req, fp, code, msg, headers, newUrl):
        return None
passmanager = urllib.request.HTTPPasswordMgrWithDefaultRealm()
passmanager.add_password(None, baseurl, username, password)
How to implement curl -u in Python?