我是编程新手。.我使用python创建代码,以使用请求包从API获取数据,并且请求使用HTTPBasicAuth。以下是在通用python中正常工作的请求。
response = requests.get(url,auth=HTTPBasicAuth('username','password'),stream=True
请提供一些建议,告诉我如何在Django中实现该功能。当我使用以下相同的代码时,由于“未定义名称HTTPBasicAuth”,它给我一个错误
def index(request):
if request.method == "POST":
url = urlname
response = requests.get(url,auth=HTTPBasicAuth('username','password'),stream=True
data = response.json()
答案 0 :(得分:0)
您还可以使用:HTTPDigestAuth
def LCS(i, j, lcs): # i , j are the position of character in X and Y respectively which are being compared
# lcs is the string storing the current longest common subsequence
print(i, j, lcs)
if i == 0 or j == 0: # basic case
return lcs
if X[i - 1] == Y[j - 1]: # increment lcs
lcs = X[i - 1] + lcs
return lcs
# else check for LCS(i-1,j) and LCS(i,j-1)
lcs_copy = str(lcs)
lcs1 = LCS(i - 1, j, lcs_copy)
x = len(lcs1)
lcs_copy = str(lcs)
lcs2 = LCS(i, j - 1, lcs_copy)
y = len(lcs2)
if x > y:
lcs = lcs1
else:
lcs = lcs2
return lcs
X = 'abcbddab'
Y = 'bdcaba'
lcs = ''
lcs = LCS(8, 6, lcs)
print(lcs)