[Python] How to use a web proxy with HttpNtlmAuth - auth_header_value is negotiate

Discussão em 'Python' iniciado por Stack, Julho 8, 2025.

  1. Stack

    Stack Membro Participativo

    I have the below. If I take out , proxies=proxies and try and connect to the Intranet, it works, I get a response back.

    However if I try an external site with the above put in (as per my example below), I get a 407 error

    import requests
    from requests_ntlm import HttpNtlmAuth
    proxies = {'http': 'http://myproxy.local:9090'}
    ntlm_auth = HttpNtlmAuth('DomainName\\MyUsername','MyPassword')
    res = requests.get("https://bbc.co.uk",auth=ntlm_auth, proxies=proxies)
    print(res.content)


    Am I doing something obviously incorrect? When I go to IE and look at the proxy information there, this is exactly what I am using

    UPDATE

    import requests
    from requests_ntlm import HttpNtlmAuth
    ntlm_auth = HttpNtlmAuth("DomainName\\MyUsername","MyPassword")
    proxies = {'http': 'http://myproxy.local:9090'}

    s = requests.Session()
    s.proxies = proxies
    s.auth = ntlm_auth

    res = s.get("http://bbc.co.uk")
    print(res.content)


    I get the following:

    [​IMG]

    When outputting the value of auth_header_value I get negotiate

    Continue reading...

Compartilhe esta Página