Django Celery 报错无法序列化

Django Celery Error Message Cannot Serialize

当我在我的 Djano 应用程序上 运行 我的脚本时,我不断收到此错误消息。 (WSGIRequest 类型的对象不是 JSON 可序列化的)当我将序列化程序设置为 JSON 时。如果我将其更改为 Pickle,则会收到此错误消息。 (无法序列化“_io.BufferedReader”对象)。我花了几天时间试图弄清楚如何解决这个问题。我感谢任何帮助。谢谢

这是我发送给 celery 的脚本。

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")

所以这个解决方案是删除请求作为参数并解决了问题。