Skip to content

Instantly share code, notes, and snippets.

@RaMSFT
Created November 15, 2021 19:14
Show Gist options
  • Select an option

  • Save RaMSFT/9ae9e417b6000a850655cbba7dbbe673 to your computer and use it in GitHub Desktop.

Select an option

Save RaMSFT/9ae9e417b6000a850655cbba7dbbe673 to your computer and use it in GitHub Desktop.
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