我正在尝试制作一个 Twitter 机器人,它使用请求库从 nytimes api 获取数据。
代码中有一行
resp = requests.get(API_ENDPOINT, my_params)
现在,当我在本地运行它时,效果非常好。所以我把它上传到pythonanywhere。当我尝试运行它时,出现以下错误:
resp = requests.get(API_ENDPOINT, my_params)
TypeError: get() takes exactly 1 argument (2 given)
发生了什么事?我最近开始使用 requests 以及 pythonanywhere 。所以我真的不知道从哪里开始调试。
最佳答案
您在 PythonAnywhere 和本地安装了不同的 requests
版本。
据我所知,PythonAnywhere 上安装的 requests
版本是 2.4.0
。那时,你必须 specify params
keyword argument explicitly :
requests.get(url, **kwargs)
你必须写:
resp = requests.get(API_ENDPOINT, params=my_params)
在最新版本(目前为2.10.0
)中,您可以指定params
as a positional argument :
requests.get(url, params=None, **kwargs)
resp = requests.get(API_ENDPOINT, my_params)
关于python - 请求 : Module works locally but failed on pythonanywhere,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37902363/