QrLogin and QrSession

class qqqr.qr.QR(png, sig, expired=False)

Class QR represents a QR code.

png: Optional[bytes]

QR code content. If None, the QR is pushed to user’s client.

expired: bool = False

Whether the QR code is expired.

property pushed

Whether the QR code is pushed to user’s client.

class qqqr.qr.QrSession(first_qr, login_sig, *, create_time=None, refresh_times=0)
refreshed

QR code refresh times counter.

current_qr

A QrSession keeps a QR object as current QR code.

new_qr(qr)

Add a new QR code to this session.

class qqqr.qr.QrLogin(client, uin, h5=True, app=None, proxy=None, info=None, *args, **kwds)
async new(no_push=False)

Create a QrSession. This method will:

  1. GET xlogin url to get pt_login_sig cookie;

  2. Try “quick login” (the QR code is pushed to user’s client);

  3. Whether the QR code is pushed or not, a QR object is created and is hold by the returned QrSession.

参数:

no_push – Do not try to push the QR code to user’s client.

返回类型:

QrSession

返回:

a QrSession

在 1.8.3 版本发生变更: Added no_push param.

async show(push_qr=False)

This method will call ptqrshow api and wrap the response QR bytes into QR.

参数:

push_qr – push QR to mobile client.

返回类型:

QR

返回:

a QR object.

async poll(sess)

Poll QR status.

抛出:

aiohttp.ClientResponseError – if response status code != 200

返回类型:

PollResp

返回:

a poll response object

async login(*, refresh_times=6, poll_freq=3, no_push=False)

Loop until cookie is returned or max refresh_times exceeds.

  • This method will emit qr_fetched event if a new qrcode is fetched.

  • If the QR code is not scanned after refresh_times, it will raise UserTimeout.

  • If refresh is set, it will refresh qrcode at once without increasing expire counter.

  • If cancel is set, it will raise UserBreak before next polling.

参数:
  • refresh_times (int) – max qr expire times.

  • poll_freq (float) – interval between two status polling, in seconds, default as 3.

  • no_push – Do not try to push the QR code to user’s client.

抛出:
  • UserTimeout – if the QR code is not scanned after refresh_times expires.

  • UserBreak – if cancel is set.

在 1.8.3 版本发生变更: Added no_push param.