ImportError: No module named 'httplib'

原因:Python 2.x中的"httplib"模块在Python 3.x中变成了"http.client"

原代码:

import httplib
import urllib

reqheaders={
'MobileType':'Android',
'DeviceToken':'xxxxxxxxx',
'OSVersion':'1.0.3',
'AppVersion':'14',
'Host':'192.xxx.x.xxxx'}  

reqconn=httplib.HTTPConnection("192.xxx.x.xxxx")
reqconn.request("GET", "/Login?username=1416&password=123", None, reqheaders)
res=reqconn.getresponse()
print res.status,  res.reason
print res.msg
print res.read()

修改后代码:

import http.client    #修改引用的模块
import urllib

reqheaders={
'MobileType':'Android',
'DeviceToken':'xxxxxxxxx',
'OSVersion':'1.0.3',
'AppVersion':'14',
'Host':'192.xxx.x.xxxx'}  

reqconn=http.client.HTTPConnection("192.xxx.x.xxxx")  #修改对应的方法
reqconn.request("GET", "/Login?username=1416&password=123", None, reqheaders)
res=reqconn.getresponse()
print (res.status,  res.reason)
print (res.msg)
print (res.read())

参考资料

原文:https://www.cnblogs.com/liutong3310/p/3741813.html

原文地址:https://www.cnblogs.com/xiaodai0/p/10937919.html