fix: 解决文件路径读取错误的问题;解决读取token时自带换行符的问题

This commit is contained in:
2022-12-14 16:44:48 +08:00
parent 4721805989
commit 52c246cf07
3 changed files with 10 additions and 4 deletions

View File

@ -1,11 +1,13 @@
import os
import requests import requests
from requests import exceptions from requests import exceptions
# 消除ssl告警 # 消除ssl告警
requests.packages.urllib3.disable_warnings() requests.packages.urllib3.disable_warnings()
tokenFile = open('accessToken', encoding = "utf-8") currentPath = os.path.dirname(__file__)
token = tokenFile.read() tokenFile = open(os.path.join(currentPath, 'accessToken'), encoding = "utf-8")
token = tokenFile.read().splitlines()[0]
tokenFile.close() tokenFile.close()
headers = { 'Authorization': f'Bearer {token}', 'Content-Type': 'application/json', 'User-Agent': 'Hiiragi/bangumi-mail-notification' } headers = { 'Authorization': f'Bearer {token}', 'Content-Type': 'application/json', 'User-Agent': 'Hiiragi/bangumi-mail-notification' }

View File

@ -1,8 +1,10 @@
import os
import re import re
from functools import partial from functools import partial
def getTemplate(filePath): def getTemplate(filePath):
file = open(filePath, encoding='utf-8') currentPath = os.path.dirname(__file__)
file = open(os.path.join(currentPath, filePath), encoding='utf-8')
fileData = file.read() fileData = file.read()
file.close() file.close()
return fileData return fileData

View File

@ -1,7 +1,9 @@
import yaml import yaml
import os
def loadYaml(path): def loadYaml(path):
file = open(path, encoding='utf-8') currentPath = os.path.dirname(__file__)
file = open(os.path.join(currentPath, path), encoding='utf-8')
configData = file.read() configData = file.read()
file.close() file.close()