An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
August 25, 2021 11:30 pm GMT
Original Link: https://dev.to/ayabouchiha/sending-put-request-in-python-670
Sending PUT Request In Python
What's the PUT request
PUT: is a request used for creating or updating a resource in a specific server.
installation
pip install requests
Sending PUT requests in Python using requests
import requestsimport JSONurl = 'https://jsonplaceholder.typicode.com/posts/1'data = {'id':1, 'userId':2, 'title':'drink water', 'body':'drinking water is important'}headers = {'Content-Type':'application/json; charset=UTF-8'}response = requests.put(url, data=json.dumps(data), headers=headers)# 200print(response.status_code)# Trueprint(response.ok)# b'{
"id": 1,
"userId": 2,
"title": "drink water",
"body": "drinking water is important"
}'print(response.content)# {# "id": 1,# "userId": 2,# "title": "drink water",# "body": "drinking water is important" # }print(response.text)# <class 'str'>print(type(response.text))# https://jsonplaceholder.typicode.com/postsprint(response.url)# application/json; charset=utf-8print(response.headers['Content-Type'])# utf-8print(response.encoding)
tutorials to learn requests
- Python Requests Tutorial: Request Web Pages, Download Images, POST Data, Read JSON, and More
- Requests in Python | Python Request Tutorial | Python Tutorial For Beginners | Edureka
- Python Requests Tutorial
- python-requests
Suggested posts
Happy coding!
Original Link: https://dev.to/ayabouchiha/sending-put-request-in-python-670
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To