(self)
| 92 | AppLog.exception(e) |
| 93 | |
| 94 | def run(self): |
| 95 | AppLog.info('start login github') |
| 96 | try: |
| 97 | req = requests.get(self.Url, |
| 98 | auth=HTTPBasicAuth(self.account, self.password)) |
| 99 | retval = req.json() |
| 100 | if retval.get('message', '') == 'Bad credentials': |
| 101 | Signals.loginErrored.emit( |
| 102 | QCoreApplication.translate('Repository', |
| 103 | 'Incorrect account or password')) |
| 104 | AppLog.warn('Incorrect account or password') |
| 105 | LoginThread.quit() |
| 106 | return |
| 107 | if 'login' not in retval: |
| 108 | Signals.loginErrored.emit( |
| 109 | QCoreApplication.translate('Repository', |
| 110 | 'Login failed, Unknown reason')) |
| 111 | AppLog.warn('Login failed, Unknown reason') |
| 112 | LoginThread.quit() |
| 113 | return |
| 114 | # 用户ID |
| 115 | uid = retval.get('id', 0) |
| 116 | AppLog.debug('user id: {}'.format(uid)) |
| 117 | # 用户昵称 |
| 118 | name = retval.get('name', 'Unknown') |
| 119 | AppLog.debug('user name: {}'.format(name)) |
| 120 | # 用户头像地址 |
| 121 | avatar_url = retval.get('avatar_url', '') |
| 122 | if avatar_url: |
| 123 | # 获取头像 |
| 124 | self.get_avatar(uid, avatar_url) |
| 125 | Signals.loginSuccessed.emit(str(uid), name) |
| 126 | except ConnectTimeout as e: |
| 127 | Signals.loginErrored.emit( |
| 128 | QCoreApplication.translate('Repository', 'Connect Timeout')) |
| 129 | AppLog.exception(e) |
| 130 | except ConnectionError as e: |
| 131 | Signals.loginErrored.emit( |
| 132 | QCoreApplication.translate('Repository', 'Connection Error')) |
| 133 | AppLog.exception(e) |
| 134 | except Exception as e: |
| 135 | Signals.loginErrored.emit( |
| 136 | QCoreApplication.translate('Repository', 'Unknown Error')) |
| 137 | AppLog.exception(e) |
| 138 | |
| 139 | AppLog.info('login thread end') |
| 140 | LoginThread.quit() |
| 141 | |
| 142 | |
| 143 | class ProgressCallback(RemoteCallbacks): |
no test coverage detected