auth_encoded = base64.encodestring('%s:%s' % (username, password))[:-1]
req = urllib.request.Request('https://somewebsite.com')
req.add_header('Authorization', 'Basic %s' % auth_encoded)
Read https url from Python with basic access authentication