Preface:
The following common functions are included in the script:
(1) Real-time access to the current time
(2) while loop submit
(3) Uploading image files
I. Explanation of the above functions:
(1) real-time access to the current time, the following shows three kinds of formatting after the date of the code examples
#!/usr/bin/python # -*- coding: UTF-8 -*- import time # Formatted into the form 2016-03-20 11:45:39 print ("%Y-%m-%d %H:%M:%S", ()) # Formatted into Sat Mar 28 22:24:24 2016 form print ("%a %b %d %H:%M:%S %Y", ()) # Convert format strings to timestamps a = "Sat Mar 28 22:24:24 2016" print ((a,"%a %b %d %H:%M:%S %Y"))
The above example outputs the results:
2016-04-07 10:25:09
Thu Apr 07 10:25:09 2016
1459175064.0
View details,/python/
(2) while loop submit
Its basic form is:
while condition of judgment(condition): executable statement(statements)……
Specific view,/python/
(3) Uploading image files
filexxxx ={ "filexxxxxxxx":open('','rb')# File contents modified according to the actual path }
Specific viewhttps:///article/
II. Examples of expected results
III. Example of a complete script:
Note: the script contains redundant extraneous code information that I'm writing here just for my own records
Modify userId, mac can correspond to the upload of different people, different devices pass records
import random import time import requests def test_zhuce(): i=1 while i<1000: url=":8888/xxxx/robot/uploadVisitorOutIn" url1 = "/xxx/app/2.1.0/token/signxxx" r1=(url1) t = ()["token"] b=(1,100000) date = { # "name": "interface registration %d" % b, "userId": "8d92402b9f859d", "userType" : 5, "operateType": 1, # "msToken": t, # Get time information in real time "time": ("%Y-%m-%d %H:%M:%S", ()), "mac": "qwertyuioo", "ageType":0, "emotionType":0, "genderType":0, "stranger":"false", "openWay":0, "temperature":0.0 } #Upload image, the file in open('','rb') is placed inside the project, if not, you need to add the corresponding file path files={ "picFile":open('','rb'), } r = (url, data=date,files=files) print('\n'"Status:",) print('\n'"Header information:",) print('\n'"Cookie information:",) print('\n'"token information:",t) i+=1 # assert r.status_code == 200
to this article on the use of python + request through the interface to achieve the function of uploading personnel access records to this article, more related python request to achieve the content of the upload of personnel access records, please search for my previous posts or continue to browse the following related articles I hope that you will have more support for me in the future!