url = ' interface address '
r = Requests.get (URL) # send GET request
Print (R.status_code) # Prints the status code, if redirected, returns the code after the redirect
Print (r.headers) # Prints the returned header (header)
Print (r.text) # View the textual form of the returned results
R.status_code # Response Status code
R.content # byte-way response body, will automatically decode for you gzip and deflate compression
R.headers # Stores the server response header in a Dictionary object, but this dictionary is special, the dictionary key is not case-sensitive, and if the key does not exist return none
R.json () # Requests built-in JSON decoder, JSON converted to Python dictionary
R.url # If there is no redirect, that is the URL of the request, if there is a redirect, that is the redirected URL
R.encoding # View the encoded format returned
R.cookies # Get Cookies
R.raw #返回原始响应体
R.history #追踪重定向过程 (list type)
R.text #字符串方式的响应体 is automatically decoded based on the character encoding of the response header
R.content.decode (' Utf-8 ') # returns content that is garbled when printed with this method
R.raise_for_status () #失败请求 (not 200 responses) throws an exception
Logincookies = r.cookies: # Get logged in cookies
s = requests.session () # can use this method to keep the session, not every time to get cookies (only applicable to the website is a cookie, the site is token of useless)
Print (r.encoding) # View the encoded format returned
R.json # Gets the JSON returned
Verify=false # When you access an HTTPS request plus do not validate the certificate
# Open Excel file, save file as suffix xls
fp = open (' Yoyo.xls ', ' WB ') # W: write, B: Binary form
Python interface Automation Test two: Common operations