相关疑难解决方法(0)

为什么我需要'b'用Base64编码Python字符串?

在这个python示例之后,我将字符串编码为Base64,其中:

>>> import base64
>>> encoded = base64.b64encode(b'data to be encoded')
>>> encoded
b'ZGF0YSB0byBiZSBlbmNvZGVk'
Run Code Online (Sandbox Code Playgroud)

但是,如果我省略领先b:

>>> encoded = base64.b64encode('data to be encoded')
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python32\lib\base64.py", line 56, in b64encode
   raise TypeError("expected bytes, not %s" % s.__class__.__name__)
   TypeError: expected bytes, not str
Run Code Online (Sandbox Code Playgroud)

为什么是这样?

python base64 python-3.x

229
推荐指数
5
解决办法
36万
查看次数

如何通过HTTP发送二进制发布数据?

我已经从文件中读取了二进制数据.我在网上看到的大多数例子直接链接到文件,并上传整个文件.我正在寻找如何通过python中的HTTP POST从其他来源上传我已经拥有的二进制数据.

python binary post http

2
推荐指数
1
解决办法
9612
查看次数

标签 统计

python ×2

base64 ×1

binary ×1

http ×1

post ×1

python-3.x ×1