Django Celery错误消息无法序列化

时间:2020-09-18 16:52:50

标签: python django django-views celery

在Djano App上运行脚本时,我不断收到此错误消息。当我将序列化器设置为JSON时(WSGIRequest类型的对象不可JSON序列化)。如果我将其更改为Pickle,则会收到此错误消息。 (无法序列化'_io.BufferedReader'对象)。我花了几天的时间试图找出解决方法。感谢您的帮助。谢谢

这是我发送给芹菜的脚本。

def ImportSchools(request):
    print("Getting school data from SIS")
    url = ""
    payload = {}
    token = APIInformation.objects.get(api_name="PowerSchool")
    key = token.key
    headers = {'Authorization': 'Bearer {}'.format(key)}   
    response = requests.request("GET", url, headers=headers, data = payload)
    encode_xml = response.text.encode('utf8')
    pretty_xml = xml.dom.minidom.parseString(encode_xml)
    pretty_xml_str = pretty_xml.toprettyxml()
    xml_string = ET.fromstring(encode_xml)
    schools = xml_string.findall("school")
    for school in schools:
      psid = school.find("id").text
      name = school.find("name").text
      school_number = school.find("school_number").text
      low_grade = school.find("low_grade").text
      high_grade = school.find("high_grade").text
    
      if not School.objects.filter(schoolpsid=psid):
        print("Record doesn't exist in DB, creating record.")  
        x = School.objects.create(schoolpsid=psid, school_name=name, school_number=school_number, low_grade=low_grade, high_grade=high_grade)
        x.save()
      elif School.objects.filter(schoolpsid=psid).exists():
        print("Record exists in DB, updating record.")
        School.objects.filter(schoolpsid=psid).update(school_name=name, school_number=school_number, low_grade=low_grade, high_grade=high_grade)
    print("School Data Pull Complete")    
    return("Done")

1 个答案:

答案 0 :(得分:0)

因此,解决方案是删除请求作为参数,并解决了问题。