I have scheduler and cron job that is to fetch data from API in remote server.
When I try running bench execute it works but it is not working when I schedule it.
Below is the function
def fill_orders():
#example API call
x = requests.get('https://w3schools.com')
doc = frappe.new_doc('Orders')
doc.my_id = "Test ID"
doc.channel_id = "XYZABC"
doc.insert()
bench execute path_to.function.fill_orders works but when I left it in the schedule in the hooks.py file, it fails. After commenting out the line with requests.get, it works again. Any help would be appreciated.
I faced the same issue where the Cronjob was not working when I used request.get method. After some investigation, I found the below solution that worked for me.
As a workaround, I used the http.client module to make the HTTP requests. Here’s an example of how I used it to send a GET request: