这个是从azure上面获得token

import urllib.request
import urllib.parse
import json

headers ={
    "User-Agent"     :  "curl/7.55.1", # 更改以防被ban
    "Host": "login.microsoftonline.com",
    "Content-Type": "application/x-www-form-urlencoded",
}

client_id = "[自己填]" 
redirect_uri = "[自己填]"           
client_secret = '[自己填]'

data = {
    "client_id" :client_id,
    # "state" : 123,
    # "redirect_uri" : redirect_uri,
    'scope' : r"https://graph.microsoft.com/.default",
    'client_secret'  : client_secret,
    'grant_type': 'client_credentials'
}

tenant = "[自己填]"

# print(urllib.parse.urlencode(data).encode())

req = urllib.request.Request(
    f"https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token",
    headers=headers,
    # data=bytes(json.dumps(data), encoding="utf-8")
    data=urllib.parse.urlencode(data).encode(),
    method='POST',
)

token = ""
with urllib.request.urlopen(req,timeout=5) as response:
    html = response.read()
    print(html)


获得出来的token就可以继续操作了

import urllib.request
import urllib.parse


token = "[自己填]" 

headers ={
    "User-Agent"     :  "curl/7.55.1", # 更改以防被ban
    # "Host": "graph.microsoft.com",
    'Authorization' : f'Bearer {token}',
    # "Content-Type": "application/x-www-form-urlencoded",
}

print(f'Bearer {token}')
req = urllib.request.Request(
    f"https://graph.microsoft.com/v1.0/me/messages?$select=sender,subject",
    headers=headers,
    # data=bytes(json.dumps(data), encoding="utf-8")
    # data=urllib.parse.urlencode(data).encode(),
    method='GET',
)
with urllib.request.urlopen(req,timeout=5) as response:
    html = response.read()
    print(html)

然后因为不知道怎么进入邮件所以还在研究怎么做

【待续】


git

顺便摸了在git上面删除特定行数的方法。参考

在命令行中输入

git config --global filter.gitignore.clean "sed '/\*_secret_no_comment_\*$/d'"
git config --global filter.gitignore.smudge cat

delete these lines
do nothing when pulling file from repo

.gitattributes 文件当中加入

* filter=gitignore

前面是匹配文件名的通配符

于是所有行末尾为 *_secret_no_comment_* 的行数都不会被push上去。

已经push上去的需要reset。