Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.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/8/python-3.x/19.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
基数为32的int()的文本无效:';MJQXGZJAGMZA====&x27;在python 3.6.4中_Python_Python 3.x - Fatal编程技术网

基数为32的int()的文本无效:';MJQXGZJAGMZA====&x27;在python 3.6.4中

基数为32的int()的文本无效:';MJQXGZJAGMZA====&x27;在python 3.6.4中,python,python-3.x,Python,Python 3.x,因此,我正在开发一个python程序,该程序必须将指定基的用户输入和该基中的输入转换为denary。我的问题是,对于任何输入,它都会抛出错误 invalid literal for int() with base 32: 'MJQXGZJAGMZA====' 我的代码是: database =open(r'C:\Users\-\OneDrive\Documents\BaseDecoder\PyMAIN\Request.txt','w') basestr = open(r'C:\Users\-\

因此,我正在开发一个python程序,该程序必须将指定基的用户输入和该基中的输入转换为denary。我的问题是,对于任何输入,它都会抛出错误

invalid literal for int() with base 32: 'MJQXGZJAGMZA===='
我的代码是:

database =open(r'C:\Users\-\OneDrive\Documents\BaseDecoder\PyMAIN\Request.txt','w')
basestr = open(r'C:\Users\-\OneDrive\Documents\Base Decoder\base.txt','r')
inputstr = open(r'C:\Users\-\OneDrive\Documents\Base Decoder\input.txt','r')
currentID = open(r'C:\Users\-\OneDrive\Documents\Base Decoder\PyMAIN\id.txt','r+')

ALLLINESID = currentID.readlines()
ID = int(ALLLINESID[len(ALLLINESID)-1])
currentID.write(str(ID + 1))

database.write(" ")
database.write(str(ID))

realinputstr = inputstr.read().replace('\n', '')
realbasestr = basestr.read().replace('\n', '')
print(realinputstr)
database.write(chr(int(str(realinputstr),int(realbasestr))))

database.close()
basestr.close()
inputstr.close()
currentID.close()
编辑: 在档案中—

request.txt为空

id.txt:

0

一,

base.txt:

三十二

input.txt:


MJQXGZJAGMZA===/p>这看起来像RFC4648中的Base32数据编码。您可以使用
base64.b32decode
函数对其进行解码

In [1]: import base64

In [2]: base64.b32decode('MJQXGZJAGMZA====')
Out[2]: b'base 32'

您可以看到,这实际上是一个使用Base32编码的字符串。

这看起来像RFC4648中的Base32数据编码。您可以使用
base64.b32decode
函数对其进行解码

In [1]: import base64

In [2]: base64.b32decode('MJQXGZJAGMZA====')
Out[2]: b'base 32'

您可以看到这实际上是一个使用base 32编码的字符串。

您确定它是base 32吗?因为
Z
显然不在范围内。在我看来像base64。
base64.b64解码(“MJQXGZJAGMZA===”)
做了些什么。@Jean-Françoisfare:Z的值是25,根据RFC 4648。你确定它是base32吗?因为
Z
显然不在范围内。在我看来像base64。
base64.b64解码(“MJQXGZJAGMZA===”)
做了些什么。@Jean-Françoisfare:Z的值为25,根据RFC4648。