requests.history 在 Zapier 上返回空输出

requests.history returning empty output on Zapier

在 'Code by Zapier'-zap 中,我正在尝试检查 url 以进行重定向。但是 requests-package 似乎没有给我历史。

import requests
response = requests.get('http://www.google.com', allow_redirects=True)
response.raise_for_status()

return [{'response':response.history}]

此代码 returns 始终为空输出。但是 Zapier 说 requests-package 在他们的服务中可用。

谁能告诉我我做错了什么?或者这在 Zapier 上根本不可用?

来自 Zapier 平台团队的 David。

Requests 在我们的 python 代码步骤中确实可用!所以那部分工作正常。

根据 documentationresponse.history 仅在发生任何重定向时才填充数组。你选择了一个不幸的例子,结果证明你可以通过 http:

访问 google
% curl http://www.google.com -I
HTTP/1.1 200 OK
...

如果您在没有 www 的情况下访问它,您会看到您期望的重定向:

% curl http://google.com -I
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/

您也可以在 python 代码中看到这一点:

>>> import requests
>>> response = requests.get('http://google.com') # redirects by default
>>> response.history
[<Response [301]>]

如果您还有其他问题,请告诉我!