python中的for循环出错。。循环工作不正常
我想获取JSON的所有记录,所以我尝试执行以下操作,但对于单个请求,它工作得很好,但当我放入循环时,它显示预期的缩进块错误python中的for循环出错。。循环工作不正常,python,python-requests,Python,Python Requests,我想获取JSON的所有记录,所以我尝试执行以下操作,但对于单个请求,它工作得很好,但当我放入循环时,它显示预期的缩进块错误 import requests url = "https://www.example.com/web/api/Profile/info" headers = { 'Content-Type': "application/x-www-form-urlencoded", 'Access-Control-Allow-Origin': "*", 'Acce
import requests
url = "https://www.example.com/web/api/Profile/info"
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'Access-Control-Allow-Origin': "*",
'Accept-Encoding': "gzip, deflate",
'Accept-Language': "en-US"
}
n = 10
sum = 0
for i in range(1,n):
payload = "user_id=1"
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text+",")
sum = sum + i
正如回溯中所建议的,for循环中缺少缩进
import requests
url = "https://www.example.com/web/api/Profile/info"
headers = {
'Content-Type': "application/x-www-form-urlencoded",
'Access-Control-Allow-Origin': "*",
'Accept-Encoding': "gzip, deflate",
'Accept-Language': "en-US"
}
n = 10
sum = 0
for i in range(1,n):
payload = "user_id={}".format(i+1)
response = requests.request("POST", url, data=payload, headers=headers)
print(response.text+",")
sum = sum + i
但是如何循环有效载荷?是的是的闪光!快开枪@Amitkumar你已经硬编码了
有效载荷
,所以它总是一样的,你想如何循环它?@MattB。是的,我想循环它以获取所有10条记录