Import the Httplib Module report Importerror solution from a new version of the zero-learning Python series _python

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.