Python | Use Prettyprinter to Make Python Output More Beautiful, You Deserve It

Requests Module | Teach You to Get Started With Python One Hundred and Eighteen

Requests Module.In addition to using the browser to send requests to the server, we can also use the third-party module requests to use code to send requests to the server and get the results.

Requests Module.Use of the requests module


In addition to using the browser to send requests to the server, we can also use the third-party module requests to use code to send requests to the server and get the results.
# requests module is a third-party module that can be used to send network connections
# pip install requests

import requests

response = requests.get ( ' http://127.0.0.1:8090 ' )
# print(response) The result is a Response object

# content refers to the returned result, which is a binary, which can be used to transmit pictures
# print( response.content.decode ('utf8')) # decode binary to string

# The result obtained is a text
print ( response.text )

print ( response.status_code ) # 200

# If the returned result is a json string, you can parse the json string
# print( response.json ())

r = requests.get ( ' http://127.0.0.1:8090/test ' )
t = r.text # get the json string
print ( t, type(t)) # { "name" : " zhangsan " , "age" : 18}

j = r.json () # Parse the json string into the corresponding data type in python
print ( j, type(j)) # { 'name' : ' zhangsan ' , 'age' : 18}

Related Articles

Explore More Special Offers

  1. Short Message Service(SMS) & Mail Service

    50,000 email package starts as low as USD 1.99, 120 short messages start at only USD 1.00