Python3 uses requests library to carry out post account password request data method

  • 2021-01-06 00:40:18
  • OfStack

As shown below:


import urllib,json,requests
url = 'http://127.0.0.1:8000/account/login'
headers = {}
data = {'username':'asd','pwd':'123456$'}
request = requests.post(url=url, data=data,json=True . headers=headers)
response = request.content.decode()
# Those that need to carry the request header can all be written in headers Inside, data Is the request body, need to carry additional information can also be added 
print(response)
#1 Under normal circumstances, you can successfully request the return value 

If the request fails, it is a cross-domain problem or a parameter error.


Related articles: