Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';python补丁请求不能用于循环吗?_Python_Python Requests_Patch - Fatal编程技术网

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

为什么';python补丁请求不能用于循环吗?,python,python-requests,patch,Python,Python Requests,Patch,我有一个代码,我想在其中为每个用户发出补丁请求(请参阅“for user in users”中的)。循环内的打印输出如下: 5ee5eee85cb7558196e1f742 101 5ee5eee85cb7558196e1f742 108 5EF9A4 EC59BD2A2ABDD13D 242 5ee5eee85cb7558196e1f742 122 5ee5eee85cb7558196e1f742 129 5EF9A4 EC59BD2A2ABDD13D 263 5ee5eee85cb75581

我有一个代码,我想在其中为每个用户发出补丁请求(请参阅“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':,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,”编码“:无、”历史“:[],”原因“:”确定“,”cookies“:,”已用“:datetime.timedelta(微秒=91716),”请求“:,”连接“:}

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':,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,”编码“:无,“历史记录”:[],'reason':'Premission FAILED','cookies','Appeased':datetime.timedelta(微秒=102812),'request':,'connection':}

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':,'url':'https://socialpark.iti.gr:8006/users/5ef9a4ec59bd2a2aabddd13d“,”编码“:无,'历史记录':[],'原因':'确定','cookies':,'已用':datetime.timedelta(微秒=135044),'请求':,'连接':}

AB295B633D9C4B727A3C0342294FA463D5CF6A2 5ee5eee85cb7558196e1f742 129

{“内容”:b'{“状态”:“错误”,“错误”:{“代码”:412,“消息”:“客户端和服务器ETag不匹配”}},“{U内容”:True,“\U下一步”:无,“\U状态代码”:412,'标头”:{'Server':'nginx','Date':'Mon,2020年10月5日09:22:28 GMT','Content Type':'application/json','Content Length':'93','Connection':'keep alive','Access Control Allow Origin':'*'),'raw':,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,”编码“:无,“历史记录”:[],'reason':'Premission FAILED','cookies','Appeased':datetime.timedelta(微秒=134461),'request':,'connection':}

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':,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,”编码“:无,“历史记录”:[],'reason':'Premission FAILED','cookies','Appeased':datetime.timedelta(微秒=96633),'request':,'connection':}

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':,'url':'https://socialpark.iti.gr:8006/users/5ef9a4ec59bd2a2aabddd13d“,”编码“:无,“历史记录”:[],'reason':'Premission FAILED','cookies','Appeased':datetime.timedelta(微秒=89694),'request':,'connection':}

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':,'url':'https://socialpark.iti.gr:8006/users/5ee5eee85cb7558196e1f742“,”编码“:无,“历史记录”:[],'reason':'Premission FAILED','cookies':,'Appeased':datetime.timede