Sample code for 30+ languages & platforms
Chilkat2-Python

HTTP Basic Authentication Test

Demonstrates how to do HTTP basic authentication using Chilkat.

Chilkat Chilkat2-Python Downloads

Chilkat2-Python
import sys
import chilkat2

# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.

http = chilkat2.Http()

# To use HTTP Basic authentication:
http.Login = "myLogin"
http.Password = "myPassword"
http.BasicAuth = True

# Run the test using this URL with the credentials above.  
# (Works while httpbin.org keeps the test endpoint available.)
jsonResponse = http.QuickGetStr("https://httpbin.org/basic-auth/myLogin/myPassword")
if (http.LastMethodSuccess == False):
    print(http.LastErrorText)
    sys.exit()

print("Response status code: " + str(http.LastStatus))

print(jsonResponse)

# Output:

# Response status code: 200
# {
#   "authenticated": true, 
#   "user": "myLogin"
# }