因此,我正在使用celery任務隊列發出HTTP請求的django項目。json.loads()失敗
在我芹菜任務的代碼,我有:
json.loads('{"content-type": "application/json"}')
print test.headers
json.loads(test.headers)
導致:
[2012-07-19 17:02:38,536: WARNING/PoolWorker-4] '{"content-type": "application/json"}'
[2012-07-19 17:02:38,569: ERROR/MainProcess] Task core.tasks.test_run[f304bcdd-72b3-4dd5-9abb-927dc29e7f65] raised exception: ValueError('No JSON object could be decoded',)
Traceback (most recent call last):
File "/usr/local/bin/lib/python2.7/site-packages/celery/task/trace.py", line 212, in trace_task
R = retval = fun(*args, **kwargs)
File "/opt/ironman_deploy/Ironman/core/tasks.py", line 18, in test_run
json.loads(test.headers)
File "/usr/local/bin/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/local/bin/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/bin/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
No JSON object could be decoded: No JSON object could be decoded
我硬是不知道發生了什麼事...顯然JSON可以解碼的字符串,因爲它不會失敗2行以上,但是當我通過引用傳遞字符串時,它似乎窒息。
任何人都可以爲我闡明這一點嗎?
'print test.headers'的輸出顯示在芹菜命令行中的第二個代碼片段的第一行: '[2012-07-19 17:02:38,536:WARNING/PoolWorker-4] '{「content-type」:「application/json」}' ' – pdeuchler 2012-07-19 22:20:07
'test.headers'是否包含文本'[2012-07-19 17:02:38,536:WARNING/Poolworder-4]'?因爲如果是這樣,JSON解碼器將不會很開心。 – steveha 2012-07-20 00:11:19