Created
November 15, 2021 19:14
-
-
Save RaMSFT/9ae9e417b6000a850655cbba7dbbe673 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import http.client | |
| def apicall_using_requests(): | |
| url = "https://api.postcodes.io/random/postcodes" | |
| payload={} | |
| headers = {} | |
| response = requests.request("GET", url, headers=headers, data=payload) | |
| print(response.text) | |
| print(type(response.text)) | |
| def apicall_using_httpclient(): | |
| conn = http.client.HTTPSConnection("api.postcodes.io") | |
| payload = '' | |
| headers = {} | |
| conn.request("GET", "/random/postcodes", payload, headers) | |
| res = conn.getresponse() | |
| data = res.read() | |
| print(data.decode("utf-8")) | |
| print(type(data.decode("utf-8"))) | |
| apicall_using_requests() | |
| apicall_using_httpclient() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment