|
我有一个名为的脚本requests.py导入request包。该脚本无法访问包中的属性,也无法导入它们。为什么这不起作用,我该如何解决?
以下代码抛出一个AttributeError。
- import requests
- res = requests.get('http://www.google.ca')
- print(res)
复制代码
Traceback (most recent call last):
File "/Users/me/dev/rough/requests.py", line 1, in <module>
import requests
File "/Users/me/dev/rough/requests.py", line 3, in <module>
requests.get('http://www.google.ca')
AttributeError: module 'requests' has no attribute 'get'
以下代码抛出一个ImportError。
- from requests import get
- res = get('http://www.google.ca')
- print(res)
复制代码
Traceback (most recent call last):
File "requests.py", line 1, in <module>
from requests import get
File "/Users/me/dev/rough/requests.py", line 1, in <module>
from requests import get
ImportError: cannot import name 'get'
以下代码抛出一个ImportError。
- from requests.auth import AuthBase
- class PizzaAuth(AuthBase):
- """Attaches HTTP Pizza Authentication to the given Request object."""
- def __init__(self, username):
- # setup any auth-related data here
- self.username = username
- def __call__(self, r):
- # modify and return the request
- r.headers['X-Pizza'] = self.username
- return r
复制代码
Traceback (most recent call last):
File "requests.py", line 1, in <module>
from requests.auth import AuthBase
File "/Users/me/dev/rough/requests.py", line 1, in <module>
from requests.auth import AuthBase
ImportError: No module named 'requests.auth'; 'requests' is not a package
|
|