美文网首页
httplib找错

httplib找错

作者: Girl_endless | 来源:发表于2018-06-14 17:26 被阅读20次

虽然说httplib跟request比起来,用的人已经不多了,但是会写一个简单的demo还是有必要的,下面就是我初次下手写的demo,里面有一些错误,你能看出来吗?

coding=utf-8

import httplib

url = "http://www.baidu.com/"
host = "www.baidu.com"
location = "/"-------------------location在这里不是必须的
body = ''
method = "get"-----------------应该用大写的‘GET’
headers = {}

conn = httplib.HTTPConnection(host)
conn.request(method, url, body, headers)
res = conn.getresponse()

print res.status()--------------------应该是res.status,去掉括号,获取状态响应码,比如200
print res.read()
conn.close()

相关文章

网友评论

      本文标题:httplib找错

      本文链接:https://www.haomeiwen.com/subject/zbnyeftx.html