wechaty / python-wechaty

Python Wechaty is a Conversational RPA SDK for Chatbot Makers written in Python
https://wechaty.readthedocs.io/zh_CN/latest/
Apache License 2.0
1.62k stars 234 forks source link

🐛🐛 Bug Report: wrong qr code when using wxwork puppet protocol #281

Closed sir1st closed 2 years ago

sir1st commented 2 years ago

requirements

Describe your problem

unable to login by scanning the qr code. but after login with puppet using js wechaty, python-wechaty works ( this skips the scan qr code step)

Reproduce your problem

just use wxwork puppet to login the wework-com, when the qr code appears, you use the reqiured tools to scan that code, and you got the wrong response, like followings:

Error info

I got something like this after scan the qr code (note: i did use the correct scan tools (the android wework-com)) 91578f0fce597175c96d797ba714620 c21446481cd2aa5174f6500ff88b4df

huan commented 2 years ago

Pay attention to

https://github.com/wechaty/getting-started/blob/24d2ca2f2c5d52ca5c900c86ac3767da6eae85ea/examples/ding-dong-bot.ts#L28

You need to use url encode before put qrcode into url.

sir1st commented 2 years ago

For wxwork puppet, the i got the following messages: the original qrcode data is this: https://wx.work.weixin.qq.com/cgi-bin/crtx_auth?key=2675731755F395E7CF2B970981C89FE2&wx=1 and the generated link is this: 2021-12-14 10:39:57,721 - Wechaty - INFO - or you can scan qrcode from: https://wechaty.js.org/qrcode/https://wx.work.weixin.qq.com/cgi-bin/crtx_auth?key=2675731755F395E7CF2B970981C89FE2&wx=1 After i open that link and scan the qr code , i got the result in the Error Info link.

but if i use the puppet_paimon protocol, the original code works, and i can scan this qr code to login. https://wechaty.js.org/qrcode/http://weixin.qq.com/x/Q98hhYsKZH2w6zxDg6gf

Definitely, i run the same code except the different puppet token.

sir1st commented 2 years ago

Also, the wechaty-js works just fine for the same wxwork puppet... I maybe find the reason.. js-wechaty use this link... StarterBot onScan: %s(%s) - %s Waiting 2 https://wechaty.js.org/qrcode/https%3A%2F%2Fwx.work.weixin.qq.com%2Fcgi-bin%2Fcrtx_auth%3Fkey%3D1DBD6C1542BDFD5B8FFE980C27AE9E9C%26wx%3D1

sir1st commented 2 years ago

Thx, Finally it works. After i add the following code in python. Hope to make an improvement in the wechaty-python source code. Appreciate!

from urllib.parse import quote async def on_scan( qrcode: str, status: ScanStatus, _data, ): """ Scan Handler for the Bot """ print('Status: ' + str(status)) print('View QR Code Online: https://wechaty.js.org/qrcode/'+quote(qrcode))

huan commented 2 years ago

print('View QR Code Online: https://wechaty.js.org/qrcode/'+quote(qrcode))

Yes, this is the correct solution.

PR to improve the example code is welcome.