SDK版本2.2.4.1
运行人脸检测,图片是BASE64就会报错,之前版本的sdk不会出错
import base64
image = base64.b64encode(open('./user01_01.png', 'rb').read())
imageType = "BASE64"
client.detect(image, imageType)
具体报错内容如下:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
2 image = base64.b64encode(open('./user01_01.png', 'rb').read())
3 imageType = "BASE64"
----> 4 client.detect(image, imageType)
~/Documents/FastAI/anaconda3/lib/python3.6/site-packages/aip/face.py in detect(self, image, image_type, options)
66
67 data.update(options)
---> 68 return self._request(self.__detectUrl, json.dumps(data, ensure_ascii=False), {
69 'Content-Type': 'application/json',
70 })
~/Documents/FastAI/anaconda3/lib/python3.6/json/__init__.py in dumps(obj, skipkeys, ensure_ascii, check_circular, allow_nan, cls, indent, separators, default, sort_keys, **kw)
236 check_circular=check_circular, allow_nan=allow_nan, indent=indent,
237 separators=separators, default=default, sort_keys=sort_keys,
--> 238 **kw).encode(obj)
239
240
~/Documents/FastAI/anaconda3/lib/python3.6/json/encoder.py in encode(self, o)
197 # exceptions aren't as detailed. The list call should be roughly
198 # equivalent to the PySequence_Fast that ''.join() would do.
--> 199 chunks = self.iterencode(o, _one_shot=True)
200 if not isinstance(chunks, (list, tuple)):
201 chunks = list(chunks)
~/Documents/FastAI/anaconda3/lib/python3.6/json/encoder.py in iterencode(self, o, _one_shot)
255 self.key_separator, self.item_separator, self.sort_keys,
256 self.skipkeys, _one_shot)
--> 257 return _iterencode(o, 0)
258
259 def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
~/Documents/FastAI/anaconda3/lib/python3.6/json/encoder.py in default(self, o)
178 """
179 raise TypeError("Object of type '%s' is not JSON serializable" %
--> 180 o.__class__.__name__)
181
182 def encode(self, o):
TypeError: Object of type 'bytes' is not JSON serializable
太感谢了,问题解决了
这样处理一下试试呢