我想创建一个网站,该网站对我购买的服务器进行API调用,我们获取有关用户的详细信息,并使用这些详细信息来创建身份验证系统。我需要用这几行来做 导入请求
url =“ *************。com.login”
querystring = {“用户名”:“用户名”,“密码”:“密码”}
response = requests.request(“ GET”,url,headers = headers,params = querystring)
jData = response.json()
我试图将其与内置的django身份验证系统集成。 我应该怎么做。任何帮助表示感谢。
我尝试过这样的事情 类AuthenticationBackend(backends.ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
usermodel = get_user_model()
try:
#user = user.objects.get(username=username)
# API Call
lms_url = "http://"*************.com/login"
querystring = {"username":username,"password":password}
#queryString = {"username":username,"password":password}
response = requests.request("POST", lms_url, params=querystring)
jData = json.loads(response.text)
if jData['code'] == '200':
user = User.objects.get(username=username)
return user
else:
return None
url =“ *************。com / login”
querystring = {“用户名”:“用户名”,“密码”:“密码”}
response = requests.request(“ GET”,url,headers = headers,params = querystring)
jData = response.json()
答案 0 :(得分:0)
如果您想发布请求,可以使用:
request = requests.post(f'127.0.0.1/api/name={name}&password={password}')
答案 1 :(得分:0)
导入请求
url =“ ******”
querystring = {“用户名”:“ ****”,“密码”:“ ***”}#或API调用所需的任何其他参数
response = requests.request(“ GET”,url,headers = headers,params = querystring)
jData = response.json()#将响应转换为JSON格式