I’m having trouble with a ‘Code by Zapier’ zap. I want to check if a URL redirects but I’m not getting any history info. Here’s my code:
import requests
r = requests.get('https://example.com', allow_redirects=True)
r.raise_for_status()
return [{'response': r.history}]
This always gives me an empty output. Zapier says they support the requests library but it’s not working as expected. Am I doing something wrong? Or is this feature not available in Zapier?
I’ve tried different URLs and even added some headers but nothing seems to work. The response object itself seems fine but the history is always empty. Any ideas on how to get the redirection info in Zapier? Thanks for any help!
I’ve encountered this exact problem before, and it’s definitely frustrating. The issue lies in Zapier’s implementation of the requests library, which doesn’t fully support all features. For URL redirection checks, I found a workaround using the ‘Requests’ app in Zapier instead of ‘Code by Zapier’.
What worked for me was setting up a separate ‘Requests’ step where I could directly control options like ‘Follow Redirects’. This approach let me retrieve the complete response, including critical information like status codes and headers. While it’s not as seamless as executing Python code directly, it reliably delivers the redirection details needed in the Zapier environment.
hey mike, i had a similar issue. turns out zapier’s requests module is kinda limited. try using the ‘HTTP’ action instead of ‘Code’. it gives u more info bout redirects. just set the ‘follow redirects’ option to true. hope this helps!
I’ve dealt with this issue in Zapier before. The problem stems from their custom implementation of the requests library, which doesn’t fully support all features like redirect history. A reliable alternative is to use the ‘URL Encode’ action followed by a ‘GET’ request in the ‘HTTP’ app. This method allows you to capture the full response, including status codes and headers, which can indicate redirects. While it’s not as straightforward as using Python code, it’s more consistent within Zapier’s environment. Remember to enable the ‘Follow Redirects’ option in the HTTP app settings. This approach has worked well for me in similar scenarios.