在window下能正常运行,上次复制的时候因为有pkl文件(热登陆记录)所以没有生成二维码没有报错,这次给python改了改,弄了个多开,结果Windows下能正常运行,我是用pycharm敲代码的,敲完部署到linux云服务器,结果linux下没有转那个pkl文件就报错(我是为了让别人登陆的,不可能每次都用pycharm生成对应的pkl文件呀,而且热登陆也会有时效性),报错如下:
Downloading QR code.
Traceback (most recent call last):File "ItCHatAutoReturnGuest.py", line 16, in <module>guest.auto_login (hotReload=True, statusStorageDir='guest.pkl')File "/usr/lib/python2.7/site-packages/itchat/components/register.py", line 32, in auto_loginloginCallback=loginCallback, exitCallback=exitCallback)File "/usr/lib/python2.7/site-packages/itchat/components/login.py", line 49, in loginpicDir=picDir, qrCallback=qrCallback)File "/usr/lib/python2.7/site-packages/itchat/components/login.py", line 123, in get_QRutils.print_qr(picDir)File "/usr/lib/python2.7/site-packages/itchat/utils.py", line 83, in print_qrsubprocess.call(['xdg-open', fileDir])File "/usr/lib64/python2.7/subprocess.py", line 524, in callreturn Popen(*popenargs, **kwargs).wait()File "/usr/lib64/python2.7/subprocess.py", line 711, in __init__errread, errwrite)File "/usr/lib64/python2.7/subprocess.py", line 1327, in _execute_childraise child_exception
OSError: [Errno 2] No such file or directory
查看报错,我是挨着看的,直到看到 File "/usr/lib/python2.7/site-packages/itchat/utils.py", line 83, in print_qr
subprocess.call(['xdg-open', fileDir]),进行尝试才解决问题,打开对应的py文件
[root@host-1 PythonWorkbench]# vi /usr/lib/python2.7/site-packages/itchat/utils.py
行数较多,通过:set number添加行数
import re, os, sys, subprocess, copy, traceback, loggingtry:from HTMLParser import HTMLParser
except ImportError:from html.parser import HTMLParserimport requestsfrom . import configlogger = logging.getLogger('itchat')emojiRegex = re.compile(r'<span class="emoji emoji(.{1,10})"></span>')
htmlParser = HTMLParser()
try:b = u'\u2588'sys.stdout.write(b + '\r')sys.stdout.flush()
except UnicodeEncodeError:BLOCK = 'MM'
else:BLOCK = b
friendInfoTemplate = {}
for k in ('UserName', 'City', 'DisplayName', 'PYQuanPin', 'RemarkPYInitial', 'Province','KeyWord', 'RemarkName', 'PYInitial', 'EncryChatRoomId', 'Alias', 'Signature','NickName', 'RemarkPYQuanPin', 'HeadImgUrl'):friendInfoTemplate[k] = ''
for k in ('UniFriend', 'Sex', 'AppAccountFlag', 'VerifyFlag', 'ChatRoomId', 'HideInputBarFlag','AttrStatus', 'SnsFlag', 'MemberCount', 'OwnerUin', 'ContactFlag', 'Uin','StarFriend', 'Statues'):friendInfoTemplate[k] = 0
friendInfoTemplate['MemberList'] = []def clear_screen():os.system('cls' if config.OS == 'Windows' else 'clear')def emoji_formatter(d, k):''' _emoji_deebugger is for bugs about emoji match caused by wechat backstagelike :face with tears of joy: will be replaced with :cat face with tears of joy:'''
:set number
查看显示如下:
79 def print_qr(fileDir):80 if config.OS == 'Darwin':81 subprocess.call(['open', fileDir])82 elif config.OS == 'Linux':83 subprocess.call(['xdg-open', fileDir])84 else:85 os.startfile(fileDir)86
猜测可能是调用在linux桌面打开吧(win的时候就是弹出来个二维码图片在桌面),我这个默认ECS阿里云linux服务器,没有那些模块所以报错了,把83行代码注释掉,然后添加个pass,如下:
79 def print_qr(fileDir):80 if config.OS == 'Darwin':81 subprocess.call(['open', fileDir])82 elif config.OS == 'Linux':83 pass84 #subprocess.call(['xdg-open', fileDir])85 else:86 os.startfile(fileDir)87
然后再运行,就成功运行了~~~~,刚开始以为没权限创建pkl文件。。。。蛋疼,最后还是一行行看报错~~~本来只看最后一行的报错~~~特此记录下,转载请注明出处~