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

#-*-conding:utf-8-*-
importrequests,re,json,time
fromrequestsimportReadTimeout
Ding_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).text
url_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_code
content_print={str(status_codes):str(i)}
#j=json.dumps(content_print)#TypeError:Objectoftype'function'isnotJSONserializable
time.sleep(1)
except:
status()
returnstatus_codes,status
defdatas(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).text
print('发送内容:',String_textMsg)
returnString_textMsg
defTorF(status_codes):#,title
ifstatus_codes==200:
datas(status)
returndatas(status)
num=1
whilenum<99999999999:
datas(status)
num+=1
time.sleep(5)
print('已执行第'+str(num)+'次')
代码如上,在json.dumps转换的时候,报错了,类型不对。我测了一下content_print={str(status_codes):str(i)}是dict啊,而且换成list、元组都不行。在实际输出的时候能看到类型确实不对,但是这个不知道咋改了...
慕桂英4014372
浏览 595回答 2
2回答

蝴蝶不菲

TypeError:isnotJSONserializable"status"是个函数,json.dumps打印不出来。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript