-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_logs.py
35 lines (26 loc) · 929 Bytes
/
http_logs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# Script for testing http logs
import logging
import requests
import http.client
# Exemplo 1
logging.basicConfig(level=logging.DEBUG)
req = requests.get("http://ipinfo.io")
print(req.text)
# Exemplo 2
httpclient_logger = logging.getLogger("http.client")
def httpclient_logging_patch(level=logging.DEBUG):
"""Enable HTTPConnection debug logging to the logging framework"""
def httpclient_log(*args):
httpclient_logger.log(level, " ".join(args))
# mask the print() built-in in the http.client module to use
# logging instead
http.client.print = httpclient_log
# enable debugging
http.client.HTTPConnection.debuglevel = 1
httpclient_logging_patch()
req = requests.get("http://ipinfo.io")
print(req.text)
# Requests com TOR
proxies = {'http':'socks5://127.0.0.1:9050', 'https':'socks5://127.0.0.1:9050'}
print(requests.get("http://ipinfo.io", proxies=proxies).text)