python批量菜品识别的时候报错
解决429 发布于2021-09 浏览:1161 回复:1
1
收藏

requests.exceptions.ConnectionError: HTTPConnectionPool(host='api.mymemory.translated.net', port=80): Max retries exceeded with url:

网上找的教程也都试过了

s.keep_alive = False # 关闭多余连接

requests.adapters.DEFAULT_RETRIES = 5 # 增加重连次数

response.close()
s.close()

time.sleep(5)

都加了还是不行

收藏
点赞
1
个赞
共1条回复 最后由解决429回复于2021-09
#2解决429回复于2021-09

完整代码

def detect(img):
    requests.adapters.DEFAULT_RETRIES = 5  # 增加重连次数
    s = requests.session()
    s.keep_alive = False  # 关闭多余连接

    request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v2/dish"
    params = {"image":img,"top_num":1}
    access_token = 'mytoken'
    request_url = request_url + "?access_token=" + access_token
    headers = {'content-type': 'application/x-www-form-urlencoded'}

    response = s.post(request_url, data=params, headers=headers)
    time.sleep(5)
    name = response.json()['result'][0]['name']
    response.close()
    s.close()
    return name
0
TOP
切换版块