所以我使用请求python库来发出一系列请求,即回复 1 然后 回复 2 然后 回复 3问题是 req1 不断重复自身,并且不会继续使用 req2任何帮助请法典如果属实:请尝试:      session = requests.session()     r = session.get('Url').text    #req1     postdata = 'the post data'     myheader = {'the headers'}     n = session.post('Myurl ', data=postdata, headers=myheaders).text       #req2请求不断重复获取请求
                    
                    
                1 回答
 
                    
                    
                            米脂
                            
                                
                            
                        
                        
                                                
                    TA贡献1836条经验 获得超3个赞
您的缩进可能是问题所在,因为只有来自 while True 循环的缩进代码才会重复。作为回报,这将导致代码的其余部分无法运行,因为循环永远不会结束。
我还注意到一些错误是:
- 之后就没有了 - try:- except:
- 当 T in 应为小写时,它也是大写的 - Try:
- T in 也应该是大写的 - True:
- w in 应为小写 - While
一个恰当的例子是
while True:
try:
session = requests.session()
r = session.get('https://example.com').text #req1
postdata = {'data': 'data'}
myheader = {'header': 'header'}
n = session.post('https://example.com', data=postdata, headers=myheaders).text #req2
except:
# Some logic for after a error occurs
# ex:
print("Error has occured")
现在这只是挑剔的,并不是那么相关,但使用的要点是成为打字的更快版本,因此将其设置为有点多余。requests.session()requestssession
添加回答
举报
0/150
	提交
		取消
	