首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python3.2.2版本import urllib.request 提示异常

2012-03-20 
python3.2.2版本import urllib.request 提示错误Python版本是3.2.2我想用urltrieve来下载文件用IDLE编辑保

python3.2.2版本import urllib.request 提示错误

Python版本是3.2.2
我想用urltrieve来下载文件
用IDLE编辑保存之后按F5运行
import urllib.request
urladd = 'http://www.icafe8.com/icafe/archive/DisklessServer1.1.0.0.exe'
localfile = 'i:/DiskLessServer.exe'
urllib.request.urlretrieve(urladd, localfile)


运行的时候 提示
ImportError: No module named request

但是如果我单独在python shell里面运行这
import urllib.request
urladd = 'http://www.icafe8.com/icafe/archive/DisklessServer1.1.0.0.exe'
localfile = 'i:/DiskLessServer.exe'
urllib.request.urlretrieve(urladd, localfile)

是可以正常运行并且将文件下载回来的

我尝试过用
import urilib
from urllib import request
也是同样的问题、保存py文件之后运行就提示
ImportError: No module named request
在python shell里面运行就正常

不知道哪里写错了还是有什么地方需要注意的?
请各位行者指点一二

万分感谢!!


[解决办法]

Python code
import urllib.requestdef test():    try:        urladd = 'http://www.icafe8.com/icafe/archive/DisklessServer1.1.0.0.exe'        localfile = 'c:/temp/DiskLessServer.exe'        urllib.request.urlretrieve(urladd, localfile)    except (Exception) as ex:        print(ex)        if __name__=='__main__':    test() 

热点排行