pythonhttpbasic-authentication

What is the cleanest way to do HTTP POST with basic auth in Python?


What is the cleanest way to do HTTP POST with Basic Auth in Python?

Using only the Python core libs.


Solution

  • Hackish workaround works:

    urllib.urlopen("https://username:password@hostname/path", data) 
    

    A lot of people don't realize that the old syntax for specifying username and password in the URL works in urllib.urlopen. It doesn't appear the username or password require any encoding, except perhaps if the password includes an "@" symbol.