在python里若想调用其他api
def send_api(cls, host, port, request_json, endpoint):
url = "http://%s:%s" % (host, port)
http_agent = HTTPRequest(url, timeout=5)
res = http_agent.post(endpoint, request_json)
LOG.debug("send update res: %s" % res)
try:
data = res.text
LOG.debug("info: %s" % data)
return data
except Exception as e:
return e
通过打断点得知res返回的内容:
常见错误:
ModuleNotFoundError: No module named ‘http.client’; ‘http’ is not a package
解决方案:
文件名http重复,将http改名即可