Skip to content

Commit

Permalink
Merge pull request #64 from xmcp/master
Browse files Browse the repository at this point in the history
really optimize the code
  • Loading branch information
liuwons committed May 14, 2016
2 parents ddc795f + 41fd44f commit ebae801
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions wxbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import os
import sys
import traceback
import webbrowser
import pyqrcode
import requests
Expand Down Expand Up @@ -40,17 +39,13 @@ def show_image(file_path):
webbrowser.open(file_path)

class SafeSession(requests.Session):
def request(self, method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None,
timeout=None, allow_redirects=True, proxies=None, hooks=None, stream=None, verify=None, cert=None,
json=None):
def request(self, *args, **kwargs):
for i in range(3):
try:
return super(SafeSession, self).request(method, url, params, data, headers, cookies, files, auth,
timeout,
allow_redirects, proxies, hooks, stream, verify, cert, json)
except Exception as e:
print e.message,traceback.format_exc()
continue
return super(SafeSession, self).request(*args, **kwargs)
except:
pass
return super(SafeSession, self).request(*args, **kwargs)


class WXBot:
Expand Down

8 comments on commit ebae801

@qtcv
Copy link

@qtcv qtcv commented on ebae801 May 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还是有问题
[ERROR] Except in proc_msg

@xmcp
Copy link
Collaborator

@xmcp xmcp commented on ebae801 May 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WayneLiu87

这是偶尔出现还是总是出现?如果是偶尔就说明这三次尝试恰好都失败了,也只能这么处理了,因为毕竟不能无限制地重试下去

@sleshep
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xmcp
你把打印调用栈删除了干嘛,看不到错误信息了

@xmcp
Copy link
Collaborator

@xmcp xmcp commented on ebae801 May 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LiuYang007 我是这么想的:如果是偶然错误,重试几遍如果好了就不管它了;如果每次都出错,那么for外面那个调用就会抛出异常。

@qtcv
Copy link

@qtcv qtcv commented on ebae801 May 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

每次都出现,已经解决,注释掉get_group_member_name(self, uid)方法,即可正常运行,不知道会影响什么功能

@sleshep
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WayneLiu87
我已经在pull request里修复了

@qtcv
Copy link

@qtcv qtcv commented on ebae801 May 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

赞赞赞!

@qtcv
Copy link

@qtcv qtcv commented on ebae801 May 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以加你微信不,对这个项目比较关注,我的wx: 123704246

Please sign in to comment.