python 微信扫码登录故障解决

最近用 wxpy 这个模块实现微信功能,程序运行了一段时间,突然有一天扫码后,迟迟不登录,ctrl+c 终止程序后报错如下:

/usr/local/lib/python2.7/dist-packages/wxpy/api/bot.py, line 88, in __init__
    except FileNotFoundError as e:
NameError: global name 'FileNotFoundError' is not defined

于是把bot.py中88行的

except FileNotFoundError as e:

修改为:

 except IOError as e:

再次扫码登录,报错如下:

Traceback (most recent call last):
  File "./copyUSB.py", line 12, in 
    bot = wxpy.Bot()
  File "/usr/local/lib/python2.7/dist-packages/wxpy/api/bot.py", line 86, in __init__
    loginCallback=login_callback, exitCallback=logout_callback
  File "/usr/local/lib/python2.7/dist-packages/itchat/components/register.py", line 36, in auto_login
    loginCallback=loginCallback, exitCallback=exitCallback)
  File "/usr/local/lib/python2.7/dist-packages/itchat/components/login.py", line 49, in login
    picDir=picDir, qrCallback=qrCallback)
  File "/usr/local/lib/python2.7/dist-packages/itchat/components/login.py", line 123, in get_QR
    utils.print_qr(picDir)
  File "/usr/local/lib/python2.7/dist-packages/itchat/utils.py", line 83, in print_qr
    subprocess.call(['xdg-open', fileDir])
  File "/usr/lib/python2.7/subprocess.py", line 168, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 1073, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib/python2.7/subprocess.py", line 121, in _eintr_retry_call
    return func(*args)
KeyboardInterrupt

其中:

 subprocess.call(['xdg-open', fileDir]) #应该是系统调用Linux桌面程序打开二维码图片

及相关:

 File "/usr/lib/python2.7/subprocess.py", line 168, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 1073, in wait
    pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
  File "/usr/lib/python2.7/subprocess.py", line 121, in _eintr_retry_call
    return func(*args)

我怀疑是wxpy对Linux图形下的二维码处理有bug,所以决定把微信二维码显示在文本终端上:

bot = wxpy.Bot()

改为

bot = wxpy.Bot(console_qr=True)

重新运行程序,文本终端扫码登录成功。

The end.

你可能感兴趣的:(python 微信扫码登录故障解决)