使用python的Face API没有服务器响应 [英] No server response for Face APIs using python

查看:159
本文介绍了使用python的Face API没有服务器响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试文档中提供的示例python代码来上传图像并检测面部,年龄,性别。  服务器大多数时间都没有响应。  响应是间歇性的,例如,我运行
脚本五次。  对于为什么会发生这种情况一无所知。  

I have been trying the sample python code provided in the documentation to upload an image and detect face, age, gender.  The server does not respond most of the times.  The response is intermittent and happens once in say, five times I run the script.  Clueless as to why this could be happening.  




推荐答案

Hi Mhow,

Hi Mhow,

现在有效吗?分享我的代码,希望能帮到你。

Does it work now? Share my code, hope to help you.

import os,http, http.client, urllib.request, urllib.parse, urllib.error, base64

headers = {
   # Basic Authorization Sample
   # 'Authorization': 'Basic %s' % base64.encodestring('{username}:{password}'),
   'Content-type': 'application/octet-stream',
}

params = urllib.parse.urlencode({
   # Specify your subscription key
   'subscription-key': '',
   # Specify values for optional parameters, as needed
   'analyzesFaceLandmarks': 'false',
   'analyzesAge': 'true',
  'analyzesGender': 'true',
  'analyzesHeadPose': 'false',
})

try:
   conn = http.client.HTTPSConnection('api.projectoxford.ai')
   conn.request("POST", "/face/v0/detections?%s" % params, requestdata, headers)
   print("send request")
   response = conn.getresponse()
   data = response.read()
   print(data)
   conn.close()
except Exception as e:
   print("[Errno {0}] {1}".format(e.errno, e.strerror))


这篇关于使用python的Face API没有服务器响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆