ImportError: No module named ‘httplib’ [How to Solve]

Reason: the “httplib” module in Python 2. X becomes “http.Client” in Python 3. X

Original code:

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()

Modified code:

import http.client    #Modify the referenced module
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")  #Modify the corresponding method
reqconn.request("GET", "/Login?username=1416&password=123", None, reqheaders)
res=reqconn.getresponse()
print (res.status,  res.reason)
print (res.msg)
print (res.read())

Similar Posts: