Search code examples
python-2.7python-requestsurllib2urlliburlopen

i have been trying to parse a website and when using urllib2.urlopen i have been getting a error


can anyone explain me to login to this link(ftpservice.acesphere.com) through python


Solution

  • The URL you are trying to access requires NTLM authentication. You can try python-ntlm package:

    from ntlm import HTTPNtlmAuthHandler
    import urllib2
    
    url = "http://ftpservice.acesphere.com/stocks/indices/master/indicesmaster_new.ace"
    user = r'domain\user'
    password = "password"
    
    pm = urllib2.HTTPPasswordMgrWithDefaultRealm()
    pm.add_password(None, "http://ftpservice.acesphere.com/", user, password)
    auth = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(pm)
    opener = urllib2.build_opener(auth)
    urllib2.install_opener(opener)
    
    response = urllib2.urlopen(url)
    print response.read()