Forums

Can’t connect to API from scheduled task

I have a script connecting to external api on hourly basis using Requests module. It worked fine for couple of months. Now I’m getting requests.exceptions.ConnectTimeout when I run it as a scheduled task. But when I run it from console it still works ok. What is the problem?

Where are you trying to connect to? (If that's something you don't want to share publicly on the forums, just send us a private message using the "Send feedback" link.) One possibility that occurs to me is that for some reason the remote server has blacklisted the IP of the task server due to excessive connections -- which might happen if you or someone else is hitting it quite a lot.

API endpoint was http://api.travelpayouts.com/v2/prices/latest with varying parameters. I found few days ago a number of running instances of the task at the same time what was definitely wrong. I think there could be a lot of duplicating requests. Maybe it is possible to see some stats about how many requests it has produced? Anyway thank you, I think it could be the reason. I will try to ask their support

OK, do let us know if they haven't blocked anything. BTW to confirm the IP address your requests will be coming from, run this code in a scheduled task:

curl 'https://api.ipify.org?format=json'

All of your scheduled tasks will (currently) run on the same physical machine, so the IP address will be consistent between system updates.

Thank you! They confirmed that IP was blocked. Now it works ok! I think the problem was that my script have not finished its job by the time the new instance started. So it produced too many requests

Excellent! Glad we worked it out :-)