Before using the Python 2.7 version of Httplib to do interface testing, the running code is normal,
Recently started using Python 3.3, and then look at the previous code, found that import httplib error: Unresolved import:httplib,
Error when running code: Importerror:no module named ' Httplib '
Looking for a variety of data found that the original Python 2.x "httplib" module in the Python 3.x into the "http.client", it is strange to know only two versions of the difference is the print statement output in 3.x to add (), it seems to understand all the differences in detail ~
Attached code for reference, I hope we will not be this error hole ~
Code implementation in version 2.7:
Copy Code code as follows:
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 ()
Code implementation in version 3.3:
Copy Code code as follows:
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 ())
Attached reference