我正在为响应客户端运行以下代码。在sublime或pycharm中运行时,该代码可以正常工作,但在Jupyter笔记本上运行时,它不打印任何内容。我可以知道怎么了吗?我认为Jupyter有一些依赖项需要导入。在两种情况下,我都使用python 3.6版
import http.client
conn = http.client.HTTPConnection("localhost:9000")
payload = "{\"key\" : \"value\", \"array\":[\"one\",\"two\"]}"
headers = {
'content-type': "application/json",
'accept': "application/json",
'cache-control': "no-cache"
}
conn.request("POST", "/", payload, headers)
res = conn.getresponse()
if int(res.code) is 200:
print("YES")
data = res.read()
print(data.decode("utf-8"))