Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyOTP生成的代码与Google Authenticator生成的代码不匹配_Python_Google Authenticator - Fatal编程技术网

Python PyOTP生成的代码与Google Authenticator生成的代码不匹配

Python PyOTP生成的代码与Google Authenticator生成的代码不匹配,python,google-authenticator,Python,Google Authenticator,我想在Python中实现由Google Authenticator生成的代码 Google Play上的应用程序Google Authenticator为所需的服务生成两步验证 我在我的谷歌账户上设置了2FA,他们以“bsnz bwpn tji6 flto 5enn 6vd4 wji7 aaaa”的形式向我提供了密码,并注明“空格不重要” 因此,我用Python尝试了以下代码,但它不起作用 在Google Authenticator中,我已经选择了“基于时间的” 在我的计算机上运行下面的脚本的时

我想在Python中实现由Google Authenticator生成的代码

Google Play上的应用程序Google Authenticator为所需的服务生成两步验证

我在我的谷歌账户上设置了2FA,他们以“bsnz bwpn tji6 flto 5enn 6vd4 wji7 aaaa”的形式向我提供了密码,并注明“空格不重要”

因此,我用Python尝试了以下代码,但它不起作用

在Google Authenticator中,我已经选择了“基于时间的”

在我的计算机上运行下面的脚本的时间与在我的手机上安装Google Authenticator应用程序的时间相同

import pyotp, base64
totp = pyotp.TOTP( base64.b32encode("bsnz bwpn tji6 flto 5enn 6vd4 wji7 aaaa") )
print "Current OTP:" + totp.now()
Google Authenticator应用程序生成的代码与我的代码不匹配


我做错了什么?

您需要扫描二维码扫描仪生成的二维码。 您将得到如下结果:

'otpauth://totp/testegmail.com?secret=MYSECRET&issuer=Google'

这是正确的秘密。

删除秘密中的空格,pyOTP可能不会处理此问题

仅适用于智能手机(安装了Google Authenticator)