- 帖子
- 3
- 精华
- 0
- 积分
- 8
- 阅读权限
- 10
- 注册时间
- 2016-8-15
- 最后登录
- 2016-8-15
|
老师好:
我碰到的问题是这样的:
# -*- coding: utf-8 -*-
import urllib2
import json
from city import city
cityname = raw_input("please input the city name:")
citycode = city.get(cityname)
if citycode:
web = urllib2.urlopen('http://www.weather.com.cn/data/cityinfo/%s.html' % citycode)
content = urllib2.urlopen(web).read()
print content
结果:
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/Karl_Gong/PycharmProjects/untitled/test2.py
please input the city name:武汉
Traceback (most recent call last):
File "/Users/Karl_Gong/PycharmProjects/untitled/test2.py", line 10, in <module>
content = urllib2.urlopen(web).read().decode('utf-8')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 423, in open
protocol = req.get_type()
AttributeError: addinfourl instance has no attribute 'get_type'
Process finished with exit code 1
我是在mac上面用pycharm运行的,能请老师帮忙看看是什么原因吗? |
|