我尝试了纽约时报API的pynytimes Python包装包,并使用了请求,得到了以下错误
知道有什么问题吗?我如何获得查询结果
提前谢谢你
尝试1-使用请求
import requests
url = 'https://api.nytimes.com/svc/search/v2/articlesearch.json?begin_date=20100101&end_date=20100201&q=Apple%20Inc&api-key=myNYTapiKeyXXXX'
articles = requests.get(url)
尝试2使用Python包装包,pynytimes:https://github.com/michadenheijer/pynytimes
from pynytimes import NYTAPI
nytimes_apikey = "myapikeyxxxxx"
nyt = NYTAPI(nytimes_apikey)
top_stories = nyt.top_stories()
在两种情况下都收到错误消息:
Traceback (most recent call last):
File "<ipython-input-398-b09b87b0632b>", line 3, in <module>
nyt = NYTAPI(nytimes_apikey)
File "C:\ProgramData\Anaconda3\lib\site-packages\pynytimes\api.py", line 194, in __init__
self.session = requests.Session()
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\sessions.py", line 417, in __init__
self.mount('https://', HTTPAdapter())
File "C:\ProgramData\Anaconda3\lib\site-packages\requests\adapters.py", line 123, in __init__
super(HTTPAdapter, self).__init__()
TypeError: super(type, obj): obj must be an instance or subtype of type
这似乎是
Jupyter notebook
上的一个特定错误在Jupiter笔记本中使用类重新加载模块时会发生此错误
简单的解决方案是重新启动内核。
查看@Mike W'sanswer here了解更多详细信息
在jupyter笔记本中也遇到了类似的问题
对我来说,这个问题是因为我在ipython旁边使用了pdbpp(版本0.10.3),这导致了这个问题
pip uninstall pdbpp
解决了我的问题,我不再在笔记本中遇到TypeError: super(type, obj): obj must be an instance or subtype of type
相关问题 更多 >
编程相关推荐