使用 django-crontab 添加到 cron 时 python 函数给出 "No JSON object could be decoded" 错误
python function when added to cron using django-crontab gives "No JSON object could be decoded" ERROR
当我在 django shell 上执行我的 python 函数时,它执行得很好。
但是当通过 crontab 执行该函数时,它会给出 "No JSON object could be decoded" 错误。
successfully made the api call. response status is 200
Exception occured : No JSON object could be decoded
Failed to complete cronjob at ('0,30 * * * *', 'myapp.cron.pulldata', ' >> /usr/local/devops/myapp/crontab.log')
Traceback (most recent call last):
File "/usr/local/devops/provider_monitoring/env/lib/python2.7/site-packages/django_crontab/crontab.py", line 145, in run_job
func(*job_args, **job_kwargs)
File "/usr/local/devops/provider_monitoring/provider_monitoring/provider_automation/cron.py", line 49, in pulldata_and_createjira
response = response.json()
File "/usr/local/devops/provider_monitoring/env/lib/python2.7/site-packages/requests/models.py", line 866, in json
return complexjson.loads(self.text, **kwargs)
File "/opt/python-2.7.10/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/opt/python-2.7.10/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/opt/python-2.7.10/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
我正在我的代码中执行 POST 调用以 splunk rest api。
payload = {'search' : 'search index="xyz" | table a , b , c' , 'earliest_time' : '-60m' , 'output_mode' : 'json_rows' }
url = "https://localhost:8089/services/search/jobs/export"
headers = {'content-type': "application/x-www-form-urlencoded",'authorization': "xyz",'cache-control': "no-cache"}
response = requests.adapters.HTTPAdapter(pool_connections=10, pool_maxsize=10, max_retries=5, pool_block=False)
response = requests.request("POST", url, data=payload, headers=headers, verify=False)
response = response.json()
只有当我 运行 我的 cron 中的 python 函数时才会出错。
我正在使用 python 版本:2.7.10
姜戈:1.8
当您没有来自 api 的响应时,您会收到 "No JSON object could be decoded" 错误。
即使我有相同的 issue.I 正在对 splunk 进行 REST api 调用,我想收集 summary_index 每 30 minutes.So 生成的数据,我的 cron 是 运行每 30 分钟一次。但是每隔 30 分钟,api 仍在聚合数据,因此它每 30 分钟就会失败一次。
当我按时间延迟(即数据正确聚合的时间)点击 api 时,我收到了响应。
所以现在我的 cron 是这样的:
5-59/30 * * * *
此 cron 将 运行 在 5 分钟后,35 分钟后
当我在 django shell 上执行我的 python 函数时,它执行得很好。 但是当通过 crontab 执行该函数时,它会给出 "No JSON object could be decoded" 错误。
successfully made the api call. response status is 200
Exception occured : No JSON object could be decoded
Failed to complete cronjob at ('0,30 * * * *', 'myapp.cron.pulldata', ' >> /usr/local/devops/myapp/crontab.log')
Traceback (most recent call last):
File "/usr/local/devops/provider_monitoring/env/lib/python2.7/site-packages/django_crontab/crontab.py", line 145, in run_job
func(*job_args, **job_kwargs)
File "/usr/local/devops/provider_monitoring/provider_monitoring/provider_automation/cron.py", line 49, in pulldata_and_createjira
response = response.json()
File "/usr/local/devops/provider_monitoring/env/lib/python2.7/site-packages/requests/models.py", line 866, in json
return complexjson.loads(self.text, **kwargs)
File "/opt/python-2.7.10/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/opt/python-2.7.10/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/opt/python-2.7.10/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
我正在我的代码中执行 POST 调用以 splunk rest api。
payload = {'search' : 'search index="xyz" | table a , b , c' , 'earliest_time' : '-60m' , 'output_mode' : 'json_rows' }
url = "https://localhost:8089/services/search/jobs/export"
headers = {'content-type': "application/x-www-form-urlencoded",'authorization': "xyz",'cache-control': "no-cache"}
response = requests.adapters.HTTPAdapter(pool_connections=10, pool_maxsize=10, max_retries=5, pool_block=False)
response = requests.request("POST", url, data=payload, headers=headers, verify=False)
response = response.json()
只有当我 运行 我的 cron 中的 python 函数时才会出错。
我正在使用 python 版本:2.7.10 姜戈:1.8
当您没有来自 api 的响应时,您会收到 "No JSON object could be decoded" 错误。
即使我有相同的 issue.I 正在对 splunk 进行 REST api 调用,我想收集 summary_index 每 30 minutes.So 生成的数据,我的 cron 是 运行每 30 分钟一次。但是每隔 30 分钟,api 仍在聚合数据,因此它每 30 分钟就会失败一次。 当我按时间延迟(即数据正确聚合的时间)点击 api 时,我收到了响应。
所以现在我的 cron 是这样的:
5-59/30 * * * *
此 cron 将 运行 在 5 分钟后,35 分钟后