求助, httplib 遇到重定向怎么处理, Location 我取出来了,但是新的 GET 发不出去了。
2016-06-18 00:08:59 +08:00
yinshunyao
尝试了关闭当前的 HTTPConnection ,新开一个,也还是 GET 不到。抓包 GET 发不出去。初始化成功了的。没思路了
status,response = 1,''
try:
start = time.time()
if connDefault is None:
conn = HTTPConnection(self.host,timeout=60)
else:
conn = connDefault
self.headers["Content-Length"] = len(PostStr)
conn.request('POST',url,PostStr,headers=self.headers)
response = conn.getresponse()
end = time.time()
print "http_post info:",end - start,response.status
#重定向
if response.status == 302:
Location=response.getheader('Location','')
#print "http_post 302 body:",response.read()
#print 'cd_chose.aspx enter the redirect',response
print conn.request('GET',Location,headers=self.headers)
response = conn.getresponse()
status,response = 302,Location
elif response.status == 200:
status,response = 200,''
else:
status,response = response.status,'does not support'
except Exception,ex:
print 'http_post -> error:',ex
status,response = 1,ex
finally:
if connDefault is None:
conn.close()
return status,response
1 条回复
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/286596
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.