weixin_42697546
weixin_42697546
2019-12-04 20:39
采纳率: 87.5%
浏览 2.1k
已结题

python 里面的方法(函数)无法执行

图片说明

代码如下

import urllib.request as ur
import ssl
import json
import re
import smtplib
from email.mime.text import MIMEText
context = ssl._create_unverified_context()
def fasongdata(title,neirong):
    mailserver = "smtp.qq.com"  # 邮箱服务器地址
    username_send = '1715082070@qq.com'  # 邮箱用户名
    password = 'uloboyvbhdgabcbj'  # 邮箱密码:需要使用授权码
    username_recv = '1715082070@qq.com'  # 收件人,多个收件人用逗号隔开
    mail = MIMEText(neirong)
    mail['Subject'] = title
    mail['From'] = username_send  # 发件人
    mail['To'] = username_recv  # 收件人;[]里的三个是固定写法,别问为什么,我只是代码的搬运工
    # smtp = smtplib.SMTP(mailserver, port=25)  # 连接邮箱服务器,smtp的端口号是25
    smtp=smtplib.SMTP_SSL('smtp.qq.com',port=465) #QQ邮箱的服务器和端口号
    smtp.login(username_send, password)  # 登录邮箱
    smtp.sendmail(username_send, username_recv, mail.as_string())  # 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
    smtp.quit()  # 发送完毕后退出smtp
    print('发送邮件成功')
def chaxu1(token,date):
    url='https://api.moguding.net:9000/attendence/clock/v1/list'
    data_s={"currPage":"1","pageSize":"10","startTime": str(date)+" 00:00:00","planId":"aa64c3a6aea631d42b3705772e164d15","endTime":"2020-12-31 23:59:59"}
    headers = {
        'Authorization': token,
        'Content-Type': 'application/json; charset=UTF-8',
        'User-Agent': 'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; vivo X9s Build/OPM1.171019.019) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',

    }
    data = json.dumps(data_s)
    try:
        requert = ur.Request(url=url,data=data.encode(),context=context)

        print('1')
        print(ur.urlopen(requert).read().decode())
    except:
        pass
def qiandao(token,username):
    data_s={
        'country': '中国',
        'address': '湖北省 · 中国农业银行',
        'province': '湖北省',
        'city': '湖北省',
        'latitude': '30.336959',
        'type': 'START',
        'longitude': '113.429182'
    }
    url = 'https://api.moguding.net:9000/attendence/clock/v1/save'
    headers = {
        'Authorization': token,
        'Content-Type': 'application/json; charset=UTF-8',
        'User-Agent':'Mozilla/5.0 (Linux; U; Android 8.1.0; zh-cn; vivo X9s Build/OPM1.171019.019) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
    }
    data=json.dumps(data_s)
    requests=ur.Request(url=url,data=data.encode("utf-8"),headers=headers)
    try:
        html = json.loads(ur.urlopen(requests, context=context).read().decode())
        html=html['data']['createTime'][:10]
        print('我是一',username)
        print('我是二',html)
        chaxu1(token,html)
    except Exception as e:
        pass

def logo(username,passwd):
    logo_data = {
        "phone":username,
        "password":passwd,
        "loginType":"android"
    }

    request_logo = ur.Request(
        url = 'https://api.moguding.net:9000/session/user/v1/login',
        data =json.dumps(logo_data).encode(),
        headers = {
            'Content-Type':'application/json; charset=UTF-8'
        }
    )
    try:
        token = json.loads(ur.urlopen(request_logo,context=context).read().decode())['data']['token']
        qiandao(token,username)
    except Exception as e:
        datad = '<urlopen error Remote end closed connection without response>'
        if datad==str(e):
            print('网络连接超时')
        else:
            # print('账号或密码输入错误')
            return username+'账号或密码输入错误'
        pass
if __name__ == '__main__':
    # qiandao('eyJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJtb2d1ZGluZy11c2VyIiwic3ViIjoie1wibG9naW5UeXBlXCI6XCJhbmRyb2lkXCIsXCJ1c2VySWRcIjoxMDEyMjQ2Mjd9IiwiYXVkIjoibW9ndWRpbmciLCJleHAiOjE4OTEwMDU4MTUsIm5iZiI6MTU3NTM4NTcxNSwiaWF0IjoxNTc1Mzg2NjE1fQ.cNDpwYjwAIUS3bMhOQdEOQXoTpyFCx5UWQ3YBKINJEqDiVAwhV4W0ID3U19q6lNgtDUjx8yWucgrtSf0gGwMFw','123')
    list=[]
    for data in open('zhanghaomim.txt','r',encoding='utf-8'):
        data=re.sub('\n','',data)
        list.append(data)
    if len(list) % 2 == 0:
        for i in range(len(list)):
            if i%2==0:
                logo(list[i],list[i+1])
    else:
        # print('zhanghaomim.txt这个文件账号密码不完整')
        pass






  • 点赞
  • 收藏

1条回答 默认 最新

  • zz00217
    空白如空 2019-12-04 21:00
    已采纳

    可能是报错,但是抛出异常了,你打印下异常有没有出错

            html = json.loads(ur.urlopen(requests, context=context).read().decode())
            html=html['data']['createTime'][:10]
            print('我是一',username)
            print('我是二',html)
            chaxu1(token,html)
        except Exception as e:
            print(str(e));
    
    点赞 评论

相关推荐