【问题标题】:Django Celery Error Message Cannot SerializeDjango Celery 错误消息无法序列化
【发布时间】:2021-01-05 15:11:50
【问题描述】:

当我在我的 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")

【问题讨论】:

    标签: python django django-views celery


    【解决方案1】:

    所以解决方案是删除 request 作为参数并解决了问题。

    【讨论】:

      猜你喜欢
      • 2020-11-25
      • 2017-04-09
      • 2020-09-07
      • 2015-01-12
      • 2011-09-09
      • 2019-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多