Python版本2.7没有模块http.client

时间:2019-04-02 11:57:10

标签: python scripting

我已经安装了python版本3.7,并且尝试通过导入http.client模块来运行python程序,但是IDE显示警告,指出python 2.7版本没有模块http.client

import http.client

conn = http.client.HTTPConnection("www,google,com")

payload = "<atom:entry xmlns:atom=\"http://www.w3.org/2005/Atom\"\r\n    xmlns:gd=\"http://schemas.google.com/g/2005\">\r\n  <atom:category scheme=\"http://schemas.google.com/g/2005#kind\"\r\n    term=\"http://schemas.google.com/contact/2008#contact\"/>\r\n  <gd:name>\r\n     <gd:givenName>Elizabeth</gd:givenName>\r\n     <gd:familyName>Bennet</gd:familyName>\r\n     <gd:fullName>Elizabeth Bennet</gd:fullName>\r\n  </gd:name>\r\n  <atom:content type=\"text\">Notes</atom:content>\r\n  <gd:email rel=\"http://schemas.google.com/g/2005#work\"\r\n    primary=\"true\"\r\n    address=\"liz@gmail.com\" displayName=\"E. Bennet\"/>\r\n  <gd:email rel=\"http://schemas.google.com/g/2005#home\"\r\n    address=\"liz@example.org\"/>\r\n  <gd:phoneNumber rel=\"http://schemas.google.com/g/2005#work\"\r\n    primary=\"true\">\r\n    (206)555-1212\r\n  </gd:phoneNumber>\r\n  <gd:phoneNumber rel=\"http://schemas.google.com/g/2005#home\">\r\n    (206)555-1213\r\n  </gd:phoneNumber>\r\n</atom:entry>"

headers = {
'Content-Type': "text/xml",
'Authorization': "Bearer ya29.GlvfBn2_hfj3pGo2ynUXORjaXed6j4GpoogZzcoQE6JLWHFlrG84I6FDjbbWRRjniM4XHAQiYddbiUUpSVDMLDNIzrasJUu9Kt59gZzfrv6XcLok6iATmP5jSwXk",
'cache-control': "no-cache",
'Postman-Token': "5b55e4ca-2c6e-4e87-8615-e76c659d4f24"
}

conn.request("POST", "m8,feeds,contacts,default,full", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

1 个答案:

答案 0 :(得分:0)

它在Python 2中被称为httplib

确定要运行Python 2吗?快要报废了。

相关问题