我忘了提一下,我正在使用以下 CURL 来发送数据:
curl -i -H "Content-Type: application/json" -X GET "http://appdev1.ischoolcampus.com/api/assignments" -d '{"guid":"teacherones-class","isTeacher":0}'
我有一个方法 Assignments.GET() 发送一些数据和数据格式(JSON、XML 等)到...
ClientRequest.Receive(data,method) 基于格式,将其发送到 ClientRequest 中的另一个方法...
JSON(data) 使用 iSCJSON.Decode(data) 解码数据...
json.loads(data) 应该将其作为字典吐出,但它却给了我以下错误:
AttributeError: 'NoneType' object has no attribute 'loads'
每个类都在不同的模块中:
Assignments - imports:
ClientRequest - imports:
iSCJSON.
我只是通过从作业中调用 iSCJSON.Decode(json_data) 来尝试过这个,它工作得很好。我已经检查以确保 json_data 一直向下钻取后实际上具有内容,并且确实如此。
但由于某种原因,我仍然收到错误消息。
有任何想法吗?
课程:
作业
import sys
sys.path.insert(1,'/Library/Server/Web/Data/Sites/iconnect/')
import web
if 'iSCModules.mod_ClientRequest' in sys.modules:
del(sys.modules["iSCModules.mod_ClientRequest"])
if 'iSCModules.mod_ServerResponse' in sys.modules:
del(sys.modules["iSCModules.mod_ServerResponse"])
from iSCModules.mod_ClientRequest import ClientRequest
from iSCModules.mod_ServerResponse import ServerResponse
#from iSCModules.mod_iSCJSON import iSCJSON
class Assignments:
def GET(self):
sentData = web.data()
#query = iSCJSON.Decode(sentData)
print "Sent Data is: " + sentData
query = ClientRequest.Receive(sentData, 'JSON')
# \/ Replace With Code \/
print "Query from Assignments is: " + query
data = query
# /\ Replace with Code /\
return ServerResponse.Send(data, 'JSON')
客户请求
import sys
sys.path.insert(1,'/Library/Server/Web/Data/Sites/iconnect/')
import web
#if 'iSCModules.mod_iSCJSON' in sys.modules:
# del(sys.modules["iSCModules.mod_iSCJSON"])
from mod_iSCJSON import iSCJSON
class ClientRequest:
@staticmethod
def Receive(data, method):
#sentData = web.data() #Need to figure out why this doesn't work...
# Remove method from parameters, Set method using logic to determine format of data sent from client.
query = getattr(ClientRequest, method)(data)
if (query):
print "Query from ClientRequest is: " + query
return query
@staticmethod
def JSON(data):
decodedData = iSCJSON.Decode(data)
if (decodedData):
return decodedData
iSCJSON
import sys
sys.path.insert(1,'/Library/Server/Web/Data/Sites/iconnect/')
import json
class iSCJSON:
@staticmethod
def Encode(json_string, compact=False):
if (compact):
result = json.dumps(json_string,separators=(',',':'))
else:
result = json.dumps(json_string)
if ( result ):
return result
@staticmethod
def Decode(json_data, encoding=''):
print "JSON Data is: " + json_data
result = json.loads(json_data)
print "Result of iSCJSON is: " + result
if ( result ):
return result