QQ空间登录组件
Project description
QLogin
QLogin 是一个用于通过二维码进行 QQ 登录的 Python 包。它使用 QQ 提供的接口生成二维码并检查登录状态,适用于需要快速登录 QQ 的应用。
特性
- 生成二维码用于 QQ 登录
- 检查二维码的登录状态
- 返回登录成功后的 cookies 信息
- 获取当前登录用户的 QQ 资料
安装
请确保你已安装 Python 3.6 或更高版本。然后,你可以通过 pip 安装该包:
pip install qlogin
使用示例
from qlogin import QLogin
# 创建实例
qlogin = QLogin()
# 获取二维码
qr_code_base64 = qlogin.get_qr_image()
print("QR Code (Base64):", qr_code_base64)
# 检查登录状态
status = qlogin.check_login_status()
print("Login Status:", status)
# 获取用户信息
if status.get('status') == 'success':
user_info = qlogin.get_login_user_info()
print("User Info:", user_info)
属性
qrsig
- 类型:
str - 描述: QR 码的签名,用于生成 QR 码和检查登录状态。
cookies
- 类型:
dict - 描述: 登录成功后返回的 cookies 信息,包含用户的登录状态信息。
uin
- 类型:
str - 描述: 用户的 QQ 号,在登录成功后从 cookies 中提取。
g_tk
- 类型:
int - 描述: 用于进行用户请求的安全验证值。
方法
get_qr_image()
获取用于 QQ 登录的二维码,并返回其 base64 编码字符串。
- 返回值:
str- 二维码图片的 base64 编码。 - 异常:
ConnectionError: 如果无法获取二维码,抛出连接错误。ValueError: 如果未能成功获取qrsig。
check_login_status(max_retries=60, interval=3)
检查二维码的登录状态。
-
参数:
max_retries(可选): 最大重试次数,默认值为60。interval(可选): 每次检查之间的等待时间(秒),默认值为3。
-
返回值:
dict- 包含登录状态和信息的字典。- 可能的状态值:
"waiting": QR 码未失效,用户尚未扫描。"scanned": QR 码已被扫描,正在认证中。"expired": QR 码已失效,用户需重新生成二维码。"success": 登录成功,包含 cookies 信息。"error": 遇到意外的响应。
- 可能的状态值:
-
异常:
ValueError: 如果 QR 码或ptqrtoken未初始化。ConnectionError: 如果在检查登录状态时发生错误。
get_login_user_info()
获取登录的用户信息。
- 返回值:
json- 返回当前登录的 QQ 用户资料,格式为 JSON 对象。 - 异常:
ConnectionError: 如果无法获取用户信息,抛出连接错误。ValueError: 如果用户未登录。
依赖
该项目依赖于以下 Python 包:
requests: 用于进行 HTTP 请求。
许可证
该项目采用 MIT 许可证。详细信息请参见 LICENSE 文件。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
qlogin-0.1.1.tar.gz
(5.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qlogin-0.1.1.tar.gz.
File metadata
- Download URL: qlogin-0.1.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dac80a296ac8affd5cf9ced0b30abc4105ddac3a41120b91dc6457f36ff8ea46
|
|
| MD5 |
07d6441d5d72e93cb9b6802def3d5e34
|
|
| BLAKE2b-256 |
2622f444b9594f579315546dfafbd529222289d3890c11f5c2b8cc0fc7133b40
|
File details
Details for the file qlogin-0.1.1-py3-none-any.whl.
File metadata
- Download URL: qlogin-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acb4f0db2bc398f2f74f2ae8dbef5e75d795f5b3e667d86af9299dc944f3831d
|
|
| MD5 |
27d8df8409860bf7e353fd74b7f0bc61
|
|
| BLAKE2b-256 |
62b46ba2cb62e579fdaa43afd17059218622385910c41dd43a3f35e91fdb119c
|