'模块对象没有属性'get'Python错误请求? [英] 'Module object has no attribute 'get' Python error Requests?

查看:615
本文介绍了'模块对象没有属性'get'Python错误请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用'easy_insatll'
安装了请求模块,我试图运行这个 tutrorial

i just installed the Requests module by using 'easy_insatll' and i tried to run the demo code of this tutrorial,

import requests
payload = {'username': 'xxxx', 'password': 'xxxxx'}
r = requests.get('https://github.com/timeline.json')

但是我收到此错误:
AttributeError:'module'对象没有属性'get'

任何想法?
谢谢

any idea? thanks

推荐答案

您正在从请求中导入所有名称模块到您的本地命名空间,这意味着您不需要使用模块名称前缀它们:

You are importing all names from the requests module into your local namespace, which means you do not need to prefix them anymore with the module name:

>>> from requests import *
>>> get
<function get at 0x107820b18>

如果要导入带有导入请求的模块语句代替,您将模块本身添加到命名空间,您必须使用全名:

If you were to import the module with an import requests statement instead, you added the module itself to your namespace and you do have to use the full name:

>>> import requests
>>> requests.get
<function get at 0x102e46b18>

请注意,上述示例是我在翻译器中的测试中得到的。如果得到不同的结果,则导入错误的模块;检查您的python包中是否有额外的 requests.py 文件:

Note that the above examples is what I got from my tests in the interpreter. If you get different results, you are importing the wrong module; check if you have an extra requests.py file in your python package:

>>> import requests
>>> print requests.__file__
/private/tmp/requeststest/lib/python2.7/site-packages/requests/__init__.pyc

您还可以测试由请求提供的名称列表模块:

>>> print dir(requests)
['ConnectionError', 'HTTPError', 'Request', 'RequestException', 'Response', 'Session', 'Timeout', 'TooManyRedirects', 'URLRequired', '__author__', '__build__', '__builtins__', '__copyright__', '__doc__', '__file__', '__license__', '__name__', '__package__', '__path__', '__title__', '__version__', '_oauth', 'api', 'auth', 'certs', 'codes', 'compat', 'cookies', 'defaults', 'delete', 'exceptions', 'get', 'head', 'hooks', 'models', 'options', 'packages', 'patch', 'post', 'put', 'request', 'safe_mode', 'session', 'sessions', 'status_codes', 'structures', 'utils']

这篇关于'模块对象没有属性'get'Python错误请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆