Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.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/2/cmake/2.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:为什么我的base64文件名编码与应该的编码不匹配?_Python_Base64 - Fatal编程技术网

Python:为什么我的base64文件名编码与应该的编码不匹配?

Python:为什么我的base64文件名编码与应该的编码不匹配?,python,base64,Python,Base64,在Python中,我有一个base64的情况,我不太清楚--当我运行脚本时: import rebus import os # Set directory os.chdir('/Users/Ryan/') # Filename from folder filename = 'Ryan20160708.txt' # Create the base64 of the filename filenameenc = rebus.urlsafe_b64encode(filename) filebas

在Python中,我有一个base64的情况,我不太清楚--当我运行脚本时:

import rebus
import os

# Set directory
os.chdir('/Users/Ryan/')

# Filename from folder
filename = 'Ryan20160708.txt'

# Create the base64 of the filename
filenameenc = rebus.urlsafe_b64encode(filename)
filebase64 = filenameenc.rstrip()

# Print these for developer
print("Your filename is: " + filename)
print("The base64 encoded filename is: " + filebase64)
我得到以下结果:

Your filename is: Ryan20160708.txt
The base64 encoded filename is: UnlhbjIwMTYwNzA4LnR4dAoK
其中较大的脚本用于一篇API文章,我不断收到
500
错误。这时我更仔细地研究了base64名称,发现它与诸如on之类的东西不匹配,它返回
UnlhbjIwMTYwNzA4LnR4dA=
而不是
UnlhbjIwMTYwNzA4LnR4dAoK
。就在最后几个角色里


我注意到的唯一一件事是,当我将base64放入站点并将其解码回文件名时,它会返回正确的文件名(
Ryan20160708.txt
),但它下面有两个换行符。虽然我已经用
rstrip()
从中去掉了任何额外的空格,但我还是被卡住了。有什么建议吗?

如果您阅读了上面的PyPI:

您将看到rebus用于:

生成由字母数字符号组成的base64编码字符串 只是

如果你真的在寻找base64编码,我怀疑这是你想要的。您可能只需要base64,如:

import base64
import os

# Set directory
os.chdir('/Users/Ryan/')

# Filename from folder
filename = 'Ryan20160708.txt'

# Create the base64 of the filename
filenameenc = base64.b64encode(filename)
filebase64 = filenameenc.rstrip()

# Print these for developer
print("Your filename is: " + filename)
print("The base64 encoded filename is: " + filebase64)
这会给你

Your filename is: Ryan20160708.txt
The base64 encoded filename is: 'UnlhbjIwMTYwNzA4LnR4dA=='

如果您阅读了上面的PyPI:

您将看到rebus用于:

生成由字母数字符号组成的base64编码字符串 只是

如果你真的在寻找base64编码,我怀疑这是你想要的。您可能只需要base64,如:

import base64
import os

# Set directory
os.chdir('/Users/Ryan/')

# Filename from folder
filename = 'Ryan20160708.txt'

# Create the base64 of the filename
filenameenc = base64.b64encode(filename)
filebase64 = filenameenc.rstrip()

# Print these for developer
print("Your filename is: " + filename)
print("The base64 encoded filename is: " + filebase64)
这会给你

Your filename is: Ryan20160708.txt
The base64 encoded filename is: 'UnlhbjIwMTYwNzA4LnR4dA=='

您注意到您正在对编码文本调用
rstrip()
,对吗?您注意到您正在对编码文本调用
rstrip()
,对吗?