為什么我照老師的敲的,版本是2.7的,運(yùn)行程序后報(bào)錯(cuò)
#-*-coding:utf8 -*-
import urllib
import urllib2
url='http:reg.haibian.com/login/ajax_login'
#定義請求數(shù)據(jù),并且對數(shù)據(jù)進(jìn)行賦值
data={}
data['loginname']='student08@qq.com'
data['password']='96e79218965eb72c92a549dd5a330112'
#對請求數(shù)據(jù)進(jìn)行編碼
data=urllib.urlencode(data)
#將數(shù)據(jù)和url進(jìn)行連接
request=url+'?'+data
requestResponse=urllib2.urlopen(request)
Responsestr=requestResponse.read()
print(requestResponse)
為什么我照老師的敲的,版本是2.7的,運(yùn)行程序后報(bào)這個(gè):
Traceback (most recent call last):
? File "E:/Python文本程序/get.py", line 14, in <module>
? ? requestResponse=urllib2.urlopen(request)
? File "C:\Python27\lib\urllib2.py", line 154, in urlopen
? ? return opener.open(url, data, timeout)
? File "C:\Python27\lib\urllib2.py", line 427, in open
? ? req = meth(req)
? File "C:\Python27\lib\urllib2.py", line 1126, in do_request_
? ? raise URLError('no host given')
URLError: <urlopen error no host given>
2017-04-14
打印調(diào)用數(shù)據(jù)錯(cuò)了 ? ? ?應(yīng)該是print(Responsestr)。。。。。