python base64 decode
时间: 2023-07-31 19:12:08 浏览: 268
要解码Base64编码的字符串,你可以使用Python`base64`模块。以下是一个示例代码:
```python
import base64
encoded_string = 'cGh5c2ljYWw='
decoded_bytes = base64.b64decode(encoded_string)
decoded_string = decoded_bytes.decode('utf-8')
print(decoded_string)
```
在上面的示例中,我们使用`base64.b64decode()`函数解码Base64编码的字符串,并将结果转换为UTF-8编码的字符串。最后,我们打印出解码后的字符串`"pythonicall"`。
请注意,这里假设输入的Base64编码字符串是有效的,并且使用的是UTF-8编码。如果你的情况有所不同,请适当调整代码。
相关问题
python base64.b64decode
这是一个Python内置模块base64中的b64decode函数,用于将Base64编码的数据解码。具体使用方法如下:
```python
import base64
encoded_data = "SGVsbG8gV29ybGQh" # Base64编码的字符串
decoded_data = base64.b64decode(encoded_data) # 解码
print(decoded_data) # 输出:b'Hello World!'
```
解码后得到的是一个bytes类型的对象,需要根据实际情况进行进一步的处理。
python b64decode.decode
`b64decode` is a method in the `base64` module in Python. It is used to decode a Base64 encoded string back into its original form.
Here's an example of how you can use it:
```python
import base64
encoded_string = "SGVsbG8gV29ybGQh" # Base64 encoded string
decoded_bytes = base64.b64decode(encoded_string) # Decode the string
decoded_string = decoded_bytes.decode('utf-8') # Convert bytes to string
print(decoded_string) # Output: "Hello World!"
```
In the above example, the `b64decode` function decodes the `encoded_string` variable, which contains a Base64 encoded string, into bytes. The `decode` method is then used to convert those bytes back into a string using the 'utf-8' encoding. The resulting decoded string is then printed.
阅读全文