Skip to main content
 首页 » 编程设计

python之请求 : Module works locally but failed on pythonanywhere

2024年10月17日8wuhuacong

我正在尝试制作一个使用请求库从 nytimes api 获取数据的 Twitter 机器人。
代码中有一行

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)