Develop a python script to perform POST / GET requests to a remote server, using the Requests module. The script is executed successfully by invoking it in the foreground from the command line, that is, manually. However, when programming the task on the cron, the script is executed but upon reaching the line of the POST request it generates the following error:
Traceback (most recent call last): File "module_download_generic.py", line 241, in <module> download_file('20190427','todos') File "module_download_generic.py", line 41, in download_file response = requests.post(url, data=json.dumps(args), headers=headers) File "/usr/lib/python2.7/site-packages/requests/api.py", line 116, in post return request('post', url, data=data, json=json, **kwargs) File "/usr/lib/python2.7/site-packages/requests/api.py", line 60, in request return session.request(method=method, url=url, **kwargs) File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 533, in request resp = self.send(prep, **send_kwargs) File "/usr/lib/python2.7/site-packages/requests/sessions.py", line 646, in send r = adapter.send(request, **kwargs) File "/usr/lib/python2.7/site-packages/requests/adapters.py", line 516, in send raise ConnectionError(e, request=request) requests.exceptions.ConnectionError: HTTPSConnectionPool(host='ws.nperf.com', port=443): Max retries exceeded with url: /cloudV1/getFile (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f3652066390>: Failed to establish a new connection: [Errno -2] Name or service not known',))
Do I have to configure something in the cron to be able to execute the Python Requests module? What could be the cause?
The line that executes the task in cron is the following:
00 05 * * * python /home/scripts/generic/module_download_generic.py