我是Mac用户,我正在尝试使用请求模块get():
import requests
url = 'http://www.omdbapi.com/?t=star+wars&r=json'
response = requests.get(url)
dic = response.json()
for key in dic:
print key, ':', dic[key]
但我明白了:
import requests
File "/Library/Python/2.7/site-packages/requests/__init__.py", line 63, in <module>
from . import utils
File "/Library/Python/2.7/site-packages/requests/utils.py", line 24, in <module>
from ._internal_utils import to_native_string
File "/Library/Python/2.7/site-packages/requests/_internal_utils.py", line 11, in <module>
from .compat import is_py2, builtin_str, str
File "/Library/Python/2.7/site-packages/requests/compat.py", line 33, in <module>
import json
File "/Users/miguel/Desktop/json.py", line 4, in <module>
response = requests.get(url)
AttributeError: 'module' object has no attribute 'get'
我已经使用pip模块重新安装了请求库,但它没有修复。 任何的想法?感谢。
答案 0 :(得分:0)
您已经命名了自己的脚本json.py
,我们可以在追溯的最后一行看到:
File "/Users/miguel/Desktop/json.py", line 4, in <module>
不要这样做,你现在正在掩盖实际的json
模块,并且会对requests
requests.py
的能力造成一定的伤害。功能。同样,不要调用脚本struct moneyConstants {
static var tapValue = NSInteger()
static var tapMultiplier = NSInteger()
static var moneyPerSecond = NSInteger()
static var money = NSInteger()
}
。只需重命名该文件即可解决问题。