Created
June 20, 2018 10:06
-
-
Save Fanna1119/9642aa7c61478c0be3e561be33bb8476 to your computer and use it in GitHub Desktop.
Faster python3 requests using built in http.client
This file contains 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 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