stable diffusion webui 登录接口(login)api接口调用(使用Python)
def getToken(self):
print("into getToken")
headers = {'accept': "application/json", 'Content-Type': 'application/x-www-form-urlencoded'}
form = {
"username": 'root',
"password": 'root'
}
response = requests.post(url=f'{sdurl}/login/', headers=headers,data=form)
print(sdurl)
print(requests)
print(response.content)
print(response.cookies)
print(response.cookies['access-token'])
结果如下:
into getToken
http://10.17.49.178:7860
<module 'requests' from '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/requests/__init__.py'>
b'{"success":true}'
<RequestsCookieJar[<Cookie access-token=zLrjBO7psPPGfOpujRIJ8w for 10.17.49.178/>, <Cookie access-token-unsecure=zLrjBO7psPPGfOpujRIJ8w for 10.17.49.178/>]>
zLrjBO7psPPGfOpujRIJ8w
获取到的response.content中返回的是{“success”:true},而没有token,发现在cookies中是有token的,这个时候,通过获取cookies中的token
参考:https://blog.csdn.net/qq_40600379/article/details/131147790
评论区