This content originally appeared on DEV Community and was authored by Aya Bouchiha
installation
pip install requests
Sending GET requests in Python using requests
import requests
url = 'https://jsonplaceholder.typicode.com/posts/1'
response = requests.get(url)
# <Response [200]>
print(response)
# 200
print(response.status_code)
# {
# "userId": 1,
# "id": 1,
# "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
# "body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
#}
print(response.text)
# https://jsonplaceholder.typicode.com/posts/1
print(response.url)
# application\json; charset=utf-8
print(response.headers['Content-Type'])
# b'{\n "userId": 1,\n "id": 1,\n "title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",\n "body": "quia et suscipit\\nsuscipit recusandae consequuntur expedita et cum\\nreprehenderit molestiae ut ut quas totam\\nnostrum rerum est autem sunt rem eveniet architecto"\n}'
print(response.content)
# {'userId': 1, 'id': 1, 'title': 'sunt aut facere repellat provident occaecati excepturi optio reprehenderit', 'body': 'quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto'}
print(response.json())
# <class 'dict'>
print(type(response.json()))
# for more information
# print(dir(response))
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 codding!
This content originally appeared on DEV Community and was authored by Aya Bouchiha
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Aya Bouchiha | Sciencx (2021-08-22T23:55:12+00:00) Sending GET Request In Python Using Requests. Retrieved from https://www.scien.cx/2021/08/22/sending-get-request-in-python-using-requests/
" » Sending GET Request In Python Using Requests." Aya Bouchiha | Sciencx - Sunday August 22, 2021, https://www.scien.cx/2021/08/22/sending-get-request-in-python-using-requests/
HARVARDAya Bouchiha | Sciencx Sunday August 22, 2021 » Sending GET Request In Python Using Requests., viewed ,<https://www.scien.cx/2021/08/22/sending-get-request-in-python-using-requests/>
VANCOUVERAya Bouchiha | Sciencx - » Sending GET Request In Python Using Requests. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/22/sending-get-request-in-python-using-requests/
CHICAGO" » Sending GET Request In Python Using Requests." Aya Bouchiha | Sciencx - Accessed . https://www.scien.cx/2021/08/22/sending-get-request-in-python-using-requests/
IEEE" » Sending GET Request In Python Using Requests." Aya Bouchiha | Sciencx [Online]. Available: https://www.scien.cx/2021/08/22/sending-get-request-in-python-using-requests/. [Accessed: ]
rf:citation » Sending GET Request In Python Using Requests | Aya Bouchiha | Sciencx | https://www.scien.cx/2021/08/22/sending-get-request-in-python-using-requests/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.