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

标签 python python-requests pythonanywhere

我正在尝试制作一个 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/

相关文章:

python - collections.abc 的实现不一致

Python 请求.exceptions.SSLError : EOF occurred in violation of protocol

python 图像抓取器在 bing 上无法正常工作

python - IMAP4 不适用于 python anywhere 服务器,但相同的代码适用于本地主机

python - 如何通过代码重新启动pythonanywhere控制台

python - Shebang 脚本不起作用

python - 使用 lxml 处理 XML 中缺失的标签

python - 如何使用 Dask 在此 "nested"结构化数组上运行计算?

python - 在 Python 中继续引用当前时间

带文件+数据的python POST请求