问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
from datetime import datetime
import itchat
import xlrd
from apscheduler.schedulers.background import BlockingScheduler
def SentChatRoomsMsg(name, context):
itchat.get_chatrooms(update=True)
iRoom = itchat.search_chatrooms(name)
for room in iRoom:
if room['NickName'] == name:
userName = room['UserName']
break
itchat.send_msg(context, userName)
print("发送时间:" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n"
"发送到:" + name + "\n"
"发送内容:" + context + "\n")
print("*********************************************************************************")
scheduler.print_jobs()
def loginCallback():
print("***登录成功***")
def exitCallback():
print("***已退出***")
#产生二维码
itchat.auto_login()
#定义用户的昵称
send_userid='微信昵称'
#查找用户的userid
itcaht_user_name = itchat.search_friends(name=send_userid)[0]['UserName']
#利用send_msg发送消息
itchat.send_msg('Robin的微信已经登录',toUserName=itcaht_user_name)
workbook = xlrd.open_workbook("chatroomsfile\AutoSentChatroom.xls")
# workbook = xlrd.open_workbook("D:\PyCharmCode\AutoLiulishouWechat\chatroomsfile\AutoSentChatroom.xlsx")
sheet = workbook.sheet_by_name('Chatrooms')
iRows = sheet.nrows
scheduler = BlockingScheduler()
index = 1
for i in range(1, iRows):
textList = sheet.row_values(i)
name = textList[0]
context = textList[2]
float_dateTime = textList[1]
date_value = xlrd.xldate_as_tuple(float_dateTime, workbook.datemode)
date_value = datetime(*date_value[:5])
if datetime.now() > date_value:
continue
date_value = date_value.strftime('%Y-%m-%d %H:%M:%S')
textList[1] = date_value
scheduler.add_job(SentChatRoomsMsg, 'date', run_date=date_value,
kwargs={"name": name, "context": context})
print("任务" + str(index) + ":\n"
"待发送时间:" + date_value + "\n"
"待发送到:" + name + "\n"
"待发送内容:" + context + "\n"
"******************************************************************************\n")
index = index + 1
if index == 1:
print("***没有任务需要执行***")
scheduler.start()
运行结果及报错内容
Traceback (most recent call last):
File "D:/002-python all/定时发微信信息/main.py", line 49, in
scheduler = BlockingScheduler()
File "C:\Users\xubintai\anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 87, in init
self.configure(gconfig, **options)
File "C:\Users\xubintai\anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 131, in configure
self._configure(config)
File "C:\Users\xubintai\anaconda3\lib\site-packages\apscheduler\schedulers\base.py", line 702, in _configure
self.timezone = astimezone(config.pop('timezone', None)) or get_localzone()
File "C:\Users\xubintai\anaconda3\lib\site-packages\tzlocal\win32.py", line 119, in get_localzone
_cache_tz = pds.timezone(get_localzone_name())
File "C:\Users\xubintai\anaconda3\lib\site-packages\tzlocal\win32.py", line 109, in get_localzone_name
_cache_tz_name = _get_localzone_name()
File "C:\Users\xubintai\anaconda3\lib\site-packages\tzlocal\win32.py", line 77, in _get_localzone_name
raise utils.ZoneInfoNotFoundError(tzkeyname)
tzlocal.utils.ZoneInfoNotFoundError: ''
Process finished with exit code 1
我的解答思路和尝试过的方法
无法修正
PS D:\002-python all\定时发微信信息> timezone
Id : China Standard Time
DisplayName : (UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐
StandardName : 中国标准时间
DaylightName : 中国夏令时
BaseUtcOffset : 08:00:00
SupportsDaylightSavingTime : False
我想要达到的结果.
tzlocal.utils.ZoneInfoNotFoundError: ''.
怎么解决啊?
多谢。