Skip to content

Instantly share code, notes, and snippets.

@Fanna1119
Created June 20, 2018 10:06
Show Gist options
  • Save Fanna1119/9642aa7c61478c0be3e561be33bb8476 to your computer and use it in GitHub Desktop.
Save Fanna1119/9642aa7c61478c0be3e561be33bb8476 to your computer and use it in GitHub Desktop.
Faster python3 requests using built in http.client
import http.client
import ujson
def json_dump(data):
return ujson.dumps(ujson.loads(data), indent=4, escape_forward_slashes=False)
def search_web(host, url):
connection = http.client.HTTPConnection(host=host, timeout=10)
connection.request(method="GET", url=url)
response = connection.getresponse().read()
connection.close()
return response
x = json_dump(search_web('api.duckduckgo.com', "/?q=DUCKDUCKGO&format=json"))
print(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment