为了账号安全,请及时绑定邮箱和手机立即绑定

类型错误:function,json转换字典时报错

类型错误:function,json转换字典时报错

慕桂英4014372 2019-05-23 17:16:53
#-*-conding:utf-8-*-importrequests,re,json,timefromrequestsimportReadTimeoutDing_url='https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxx'Ding_headers={"Content-Type":"application/json;charset=utf-8"}url='http://www.123.com.cn/'req=requests.get(url).texturl_list=re.findall('href="(.*?)"',req,re.S)urls=['http://www.123.com.cn/']forulinurl_list:ifulnotinurls:urls.append(ul)defstatus():foriinurls:if'show'ini:try:html_status=requests.head(url=i,timeout=30)status_codes=html_status.status_codecontent_print={str(status_codes):str(i)}#j=json.dumps(content_print)#TypeError:Objectoftype'function'isnotJSONserializabletime.sleep(1)except:status()returnstatus_codes,statusdefdatas(status):datass={"msgtype":"text","text":{"content":status},"at":{"atMobiles":[],"isAtAll":False}}String_textMsg=json.dumps(datass)req=requests.post(Ding_url,data=String_textMsg,headers=Ding_headers).textprint('发送内容:',String_textMsg)returnString_textMsgdefTorF(status_codes):#,titleifstatus_codes==200:datas(status)returndatas(status)num=1whilenum
查看完整描述

2 回答

?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

TypeError:isnotJSONserializable
"status"是个函数,json.dumps打印不出来。
                            
查看完整回答
反对 回复 2019-05-23
  • 2 回答
  • 0 关注
  • 594 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信