用户名和密码
username = 'test123'
password = '12345678'
login_data =json.dumps({"captcha": "2", "agentType": 1, "clientNonce": "wcs0520240621104331267ceeh", "cuType": "4"})
创建认证对象
auth = HTTPDigestAuth(username, password)
headers = {'Content-Type': "application/json;charset=UTF-8"}
发起请求
response = requests.post(url,data=login_data,auth=auth ,headers=headers )
C:\Users\HP\PycharmProjects\IMS\venv\Scripts\python.exe C:/Users/HP/PycharmProjects/demo/testCase/testlogin1.py
2024-06-30 16:49:22,469 DEBUG Starting new HTTP connection (1): 172.16.11.206:10000
2024-06-30 16:49:22,479 DEBUG http://172.16.11.206:10000/ "POST /uas/v1/api/user/login HTTP/1.1" 401 None
2024-06-30 16:49:22,492 DEBUG http://172.16.11.206:10000/ "POST /uas/v1/api/user/login HTTP/1.1" 401 None
2024-06-30 16:49:22,492 DEBUG
Response Received:
2024-06-30 16:49:22,492 DEBUG Status Code: 401
2024-06-30 16:49:22,492 DEBUG Response Headers:
2024-06-30 16:49:22,492 DEBUG User-Agent: python-requests/2.32.3
2024-06-30 16:49:22,492 DEBUG Accept-Encoding: gzip, deflate
2024-06-30 16:49:22,492 DEBUG Accept: /
2024-06-30 16:49:22,492 DEBUG Connection: keep-alive
2024-06-30 16:49:22,492 DEBUG Content-Type: application/json;charset=UTF-8
2024-06-30 16:49:22,492 DEBUG Content-Length: 92
2024-06-30 16:49:22,492 DEBUG Authorization: Digest username="test123", realm="realm@host.com", nonce="0fee4ed0a1ba37aac880b70a5b5f002a02", uri="/uts/v1/api/user/login", response="66517571f35b931df9a05cf8bf16a9ad", opaque="null", qop="auth", nc=00000001, cnonce="23561c6f1fc10bbd"
2024-06-30 16:49:22,492 DEBUG
Response Content:
2024-06-30 16:49:22,492 DEBUG {"resultCode":100002,"resultDesc":"鉴权失败"}