为什么python补丁请求不能用于循环?

2024-09-30 01:32:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个代码,我想在其中为每个用户发出补丁请求(请参阅“for user in users”中的)。循环内的打印输出如下:

5ee5eee85cb7558196e1f742

101

5ee5eee85cb7558196e1f742

108

5EF9A4 EC59BD2A2ABDD13D

242

5ee5eee85cb7558196e1f742

122

5ee5eee85cb7558196e1f742

129

5EF9A4 EC59BD2A2ABDD13D

263

5ee5eee85cb7558196e1f742

143

5ee5eee85cb7558196e1f742

一百五十

5EF9A4 EC59BD2A2ABDD13D

284

但是,该补丁只制作了一次,并且仅用于第一个“5ee5eee85cb7558196e1f742”和第一个“5EF9A4 EC59BD2A2AABD13D”,而不是循环中的所有其他时间。有人能帮我吗

extrapoints=0    
for position in positions:
    
    
    position_type = position['position_type']
        #an kapoiois user stathmeusi
    if position_type == "parking":
            #kratame tis suntetagmenes thesis gia na doume an thn exei anaferei kapoios reporter    
        coordinatesx = position['location']['coordinates'][0]
        coordinatesy = position['location']['coordinates'][1]  
            #pame sti sullogi reports na doume an uparxoun oi suntetagmenes se kapoia anafora
        for report in reports:
                #rid = report['reporter_id']
            rcoordinatesy = report['location']['coordinates'][1]    
            rcoordinatesx = report['location']['coordinates'][0]
            #extrapoints = 0   
            if rcoordinatesx==coordinatesx and rcoordinatesy==coordinatesy:
                    #an kapoia anafora exei tetoies suntetagmenes prosthetoume 7 pontous ston reporter 
                    #rid = report['reporter_id']
                rid= report['reporter_id']
                extrapoints = extrapoints + 7
                
                
                for user in users:
                    userid = user['_id']
                    rewarding_p = user['rewarding_points']
                    if userid == rid:
                        
                       
                        etag = user['_etag']
                        print (etag)
                        rewarding_p = rewarding_p + extrapoints
                        print(userid)
                        print(rewarding_p)
                        
                        data={"rewarding_points":rewarding_p}
                        headers = {'Authorization':'Bearer 8b59cc74f15befc05b48f90d5e09866028b2b624','If-Match': etag}
                        url = 'https://socialpark.iti.gr:8006/users'
                        new_url = "{}/{}".format(url, userid)
                        r = requests.patch(new_url, data, headers=headers)
                      
                        time.sleep(2)

在这里您可以看到r的内容:

{“内容”:b{“id”:“5ee5eee85cb7558196e1f742”,“更新”:“Mon,2020年10月5日09:22:22 GMT”,“创建”:“Sun,2020年6月14日09:33:27 GMT”,“etag”:“a97daa90626ed7493010f11d2d4be6ff06e6a7be”,“链接”:“自我”:{“标题”:“用户”,“href”:“用户/5ee5eee85cb7558196e1f742”;“确定”}“,”内容“:真“,”下一步“:无,'状态代码“:200,'标题“:{'Server':'nginx','Date':'Mon,Oct 2020 09:22:22 GMT”,“内容类型“:'application/json”,“content Length':'276','Connection':'keep alive','ETag':“'a97daa90626ed7493010f11d4be6ff06e6a7be','Access Control Allow Origin':'*”,'raw':<;urllib3.response.HTTPResponse对象位于0x000001F8E9F68D08>;,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,“编码”:无,“历史记录”:[],“原因”:“确定”,“cookies”:<;RequestScookeJar[]>;,“已用”:datetime.timedelta(微秒=91716),“请求”:<;PreparedRequest[补丁]>;,“连接”:<;位于0x000001F8EA297F88的requests.adapters.HTTPAdapter对象>;}

AB295B633D9C4B727A3C0342294FA463D5CF6A2 5ee5eee85cb7558196e1f742 115 {“内容”:b'{“状态”:“错误”,“错误”:{“代码”:412,“消息”:“客户端和服务器ETag不匹配”}},“{U内容”:True,“\U下一步”:无,“\U状态代码”:412,'标头”:{'Server':'nginx','Date':'Mon,2020年10月5日09:22:24 GMT','Content Type':'application/json','Content Length':'93','Connection':'keep alive','Access Control Allow Origin':'*'},'raw':<;urllib3.response.HTTPResponse对象位于0x000001F8E9FAC6C8>;,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,“编码”:无,“历史记录”:[],“原因”:“前置条件失败”,“cookies”:<;RequestScookeJar[]>;,“已用”:datetime.timedelta(微秒=102812),“请求”:<;PreparedRequest[补丁]>;,“连接”:<;位于0x000001F8EA172088的requests.adapters.HTTPAdapter对象>;}

16b77ead1718639c2ab727aa50c6a8a669a52da9 5EF9A4 EC59BD2A2ABDD13D 263 {“内容”:b{“id”:“5EF9A4 EC59BD2A2AABDD13D”,“更新”:“Mon,2020年10月5日09:22:26 GMT”,“创建”:“Mon,2020年6月29日08:23:08 GMT”,“etag”:“fc0363f6e2b4c59a870c06e057b09c5b94dd44f5”,“链接”:“self”:{“title”:“user”,“href”:“users/5EF9A4 EC59BD2AABD13D”;“OK”“,”内容“:真“,”下一步“:无,'状态代码“:200,'标题“:{'Server':'nginx','Date':'Mon,Oct 2020 09:22:26 GMT”,“内容类型“:'application/json”,“content Length':'276','Connection':'keep alive','ETag':“'fc0363f6e2b4c59a870c06e057b0b09c0b09d44f5','Access Control Allow Origin':'*},'raw':<;urllib3.response.HTTPResponse对象位于0x000001F8EA031788>;,'url':'https://socialpark.iti.gr:8006/users/5ef9a4ec59bd2a2aabddd13d“,“编码”:无,“历史记录”:[],“原因”:“确定”,“cookies”:<;RequestScookeJar[]>;,“已用”:datetime.timedelta(微秒=135044),“请求”:<;PreparedRequest[补丁]>;,“连接”:<;位于0x000001F8E8F06C48的requests.adapters.HTTPAdapter对象>;}

AB295B633D9C4B727A3C0342294FA463D5CF6A2 5ee5eee85cb7558196e1f742 129

{“U内容”:b'{“U状态”:“错误”,“U错误”:{“代码”:412,“消息”:“客户端和服务器ETag不匹配”}},“内容已消耗”:True,“下一步”:无,“状态代码”:412,“标题”:“{“服务器”:“nginx”,“日期”:“Mon,2020年10月5日09:22:28 GMT”,“内容类型”:“应用程序/json”,“内容长度”:“93”,“连接”:“保持活动”,“访问控制允许源代码”:“*”,“原始”:;urllib3.response.HTTPResponse对象位于0x000001F8E9FACC08>;,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,“编码”:无,“历史记录”:[],“原因”:“前置条件失败”,“cookies”:<;RequestScookeJar[]>;,'已用“:datetime.timedelta(微秒=134461),“请求”:<;PreparedRequest[补丁]>;,'连接':<;位于0x000001F8EA484408的requests.adapters.HTTPAdapter对象>;}

AB295B633D9C4B727A3C0342294FA463D5CF6A2 5ee5eee85cb7558196e1f742 136

{“内容”:b'{“状态”:“错误”,“错误”:{“代码”:412,“消息”:“客户端和服务器ETag不匹配”}},“{U内容”:True,“\U下一步”:无,“\U状态代码”:412,'标头”:{'Server':'nginx','Date':'Mon,2020年10月5日09:22:30 GMT','Content Type':'application/json','Content Length':'93','Connection':'keep alive','Access Control Allow Origin':'*'},'raw':<;urllib3.response.HTTPResponse对象位于0x000001F8E9FAC048>;,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,“编码”:无,“历史记录”:[],“原因”:“前置条件失败”,“cookies”:<;RequestScookeJar[]>;,“已用”:datetime.timedelta(微秒=96633),“请求”:<;PreparedRequest[补丁]>;,“连接”:<;位于0x000001F8EA031788的requests.adapters.HTTPAdapter对象>;}

16b77ead1718639c2ab727aa50c6a8a669a52da9 5EF9A4 EC59BD2A2ABDD13D 284

{“内容”:b'{“状态”:“错误”,“错误”:{“代码”:412,“消息”:“客户端和服务器ETag不匹配”}},“{U内容”:True,“\U下一步”:无,“\U状态代码”:412,'标头”:{'Server':'nginx','Date':'Mon,2020年10月5日09:22:32 GMT','Content Type':'application/json','Content Length':'93','Connection':'keep alive','Access Control Allow Origin':'*'},'raw':<;urllib3.response.HTTPResponse对象位于0x000001F8E9FACCC8>;,'url':'https://socialpark.iti.gr:8006/users/5ef9a4ec59bd2a2aabddd13d“,“编码”:无,“历史记录”:[],“原因”:“前置条件失败”,“cookies”:<;RequestScookeJar[]>;,“已用”:datetime.timedelta(微秒=89694),“请求”:<;PreparedRequest[补丁]>;,“连接”:<;位于0x000001F8EA484188的requests.adapters.HTTPAdapter对象>;}

AB295B633D9C4B727A3C0342294FA463D5CF6A2 5ee5eee85cb7558196e1f742 一百五十

{“内容”:b'{“状态”:“错误”,“错误”:{“代码”:412,“消息”:“客户端和服务器ETag不匹配”}},“{U内容”:True,“\U下一步”:无,“\U状态代码”:412,'标头”:{'Server':'nginx','Date':'Mon,2020年10月5日09:22:34 GMT','Content Type':'application/json','Content Length':'93','Connection':'keep alive','Access Control Allow Origin':'*'},'raw':<;urllib3.response.HTTPResponse对象位于0x000001F8EA031888>;,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,“编码”:无,“历史记录”:[],“原因”:“前置条件失败”,“cookies”:<;RequestScookeJar[]>;,“已用”:datetime.timedelta(微秒=93464),“请求”:<;PreparedRequest[补丁]>;,“连接”:<;位于0x000001F8E8E969C8的requests.adapters.HTTPAdapter对象>;}

AB295B633D9C4B727A3C0342294FA463D5CF6A2 5ee5eee85cb7558196e1f742 157

{“内容”:b'{“状态”:“错误”,“错误”:{“代码”:412,“消息”:“客户端和服务器ETag不匹配”}},“{U内容”:True,“\U下一步”:无,“\U状态代码”:412,'标头”:{'Server':'nginx','Date':'Mon,2020年10月5日09:22:37 GMT','Content Type':'application/json','Content Length':'93','Connection':'keep alive','Access Control Allow Origin':'*'),'raw':<;urllib3.response.HTTPResponse对象地址0x000001F8EA484908>;,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742,“编码”:无,“历史记录”:[],“原因”:“前置条件失败”,“cookies”:<;RequestScookeJar[]>;,'已用“:datetime.timedelta(微秒=152959),“请求”:<;PreparedRequest[补丁]>;,'连接':<;位于0x000001F8EA0311C8的requests.adapters.HTTPAdapter对象>;}

16b77ead1718639c2ab727aa50c6a8a669a52da9 5EF9A4 EC59BD2A2ABDD13D 305

{“内容”:b'{“状态”:“错误”,“错误”:{“代码”:412,“消息”:“客户端和服务器ETag不匹配”}},“{U内容”:True,“\U下一步”:无,“\U状态代码”:412,'标头”:{'Server':'nginx','Date':'Mon,2020年10月5日09:22:39 GMT','Content Type':'application/json','Content Length':'93','Connection':'keep alive','Access Control Allow Origin':'*'},'raw':<;urllib3.response.HTTPResponse对象位于0x000001F8EA0B9AC8>;,'url':'https://socialpark.iti.gr:8006/users/5ef9a4ec59bd2a2aabddd13d“,“编码”:无,“历史记录”:[],“原因”:“前置条件失败”,“cookies”:<;RequestScookeJar[]>;,“已用”:datetime.timedelta(微秒=116027),“请求”:<;PreparedRequest[补丁]>;,“连接”:<;位于0x000001F8EA2DBE88的requests.adapters.HTTPAdapter对象>;}


Tags: 对象代码httpsltgturl内容状态

热门问题