我的python代码如下:
request_url = "https://aip.baidubce.com/api/v1/solution/direct/img_censor"
# 二进制方式打开图片文件
f = open(imgfile, 'rb')
img = base64.b64encode(f.read())
params = {"image":img}
params = urllib.urlencode(params)
#access_token = '[调用鉴权接口获取的token]'
request_url = request_url + "?access_token=" + access_token
request = urllib2.Request(url=request_url, data=params)
request.add_header('Content-Type', 'application/x-www-form-urlencoded')
response = urllib2.urlopen(request)
content = response.read()
if content:
print content
报错如下:
Traceback (most recent call last):
File "D:/python/test/baiduAI.py", line 53, in
response = urllib2.urlopen(request)
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 437, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 550, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 475, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 558, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 415: Unsupported Media Type
调用色情和恐暴接口都没问题,调用政治敏感和恶心图像就不行,请问各位大神这是因为什么?
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
Content-Type写错了
Content-Type:application/json;charset=utf-8
技术文档:https://ai.baidu.com/docs#/ImageCensoring-API/top