我正在尝试这个简单的代码:
import requests
print requests.__file__
r = requests.get('https://github.com/timeline.json')
当我一一键入行时,它在命令行上完美运行,但当我将其作为脚本或在 Sublime Text 2 中执行时,它就不行了。这是堆栈跟踪:
C:\Python27\lib\site-packages\requests\__init__.pyc
Traceback (most recent call last):
File "C:\Users\Bruce\Desktop\http.py", line 1, in <module>
import requests
File "C:\Python27\lib\site-packages\requests\__init__.py", line 53, in <module>
from requests.packages.urllib3.contrib import pyopenssl
File "C:\Python27\lib\site-packages\requests\packages\__init__.py", line 3, in <module>
from . import urllib3
File "C:\Python27\lib\site-packages\requests\packages\urllib3\__init__.py", line 16, in <module>
from .connectionpool import (
File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 15, in <module>
from http.client import HTTPConnection, HTTPException
File "C:\Users\Bruce\Desktop\http.py", line 3, in <module>
r = requests.get('https://github.com/timeline.json')
AttributeError: 'module' object has no attribute 'get'
[Finished in 0.2s with exit code 1]
'模块对象没有属性'get' Python错误请求的答案?没有太大帮助。
这可能是我的 ST2 Python 构建系统中的一些错误吗?我尝试通过使用并重新安装它们来删除所有requests
模块,以防有多个模块。pip