import requests
import json
import logging
# These two lines enable debugging at httplib level (requests->urllib3->http.client)
# You will see the REQUEST, including HEADERS and DATA, and RESPONSE with HEADERS but without DATA.
# The only thing missing will be the response.body which is not logged.
try:
import http.client as http_client
except ImportError:
# Python 2
import httplib as http_client
http_client.HTTPConnection.debuglevel = 1
# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
data1={}
header={
'Authorization':'Bearer 421a6942-00ec-4694-9d79-27480ed80a04',
'Content-Type':'application/json; charset=UTF-8',
}
httpbin_post = requests.post('http://10.240.50.121/api/v1/asset/query/assetlist', headers=header,
# json=data1)
data=json.dumps(data1))
print('httpbin_post: ', httpbin_post.text)
原文链接:stackoverflow