Python SDK 运行出错
VBover 发布于2018-01 浏览:3607 回复:8
0
收藏

连接API的时候报错,昨天还能用没改动代码,报错位置:

Traceback (most recent call last):
File "C:/Users/vbove/PycharmProjects/AnswerHero/start.py", line 67, in
get_results(cnt)
File "C:/Users/vbove/PycharmProjects/AnswerHero/start.py", line 37, in get_results
search = client.basicGeneral(ques)
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\aip\ocr.py", line 66, in basicGeneral
return self._request(self.__generalBasicUrl, data)
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\aip\base.py", line 89, in _request
authObj = self._auth()
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\aip\base.py", line 165, in _auth
), proxies=self._proxies).json()
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\requests\sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\requests\adapters.py", line 440, in send
timeout=timeout
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\urllib3\connectionpool.py", line 601, in urlopen
chunked=chunked)
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\urllib3\connectionpool.py", line 346, in _make_request
self._validate_conn(conn)
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\urllib3\connectionpool.py", line 850, in _validate_conn
conn.connect()
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\urllib3\connection.py", line 314, in connect
cert_reqs=resolve_cert_reqs(self.cert_reqs),
File "C:\Users\vbove\PycharmProjects\AnswerHero\venv\lib\site-packages\urllib3\util\ssl_.py", line 269, in create_urllib3_context
context.options |= options
File "E:\Program Files (x86)\Python36-32\lib\ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "E:\Program Files (x86)\Python36-32\lib\ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
File "E:\Program Files (x86)\Python36-32\lib\ssl.py", line 459, in options
super(SSLContext, SSLContext).options.__set__(self, value)
[Previous line repeated 322 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

收藏
点赞
0
个赞
共8条回复 最后由用户已被禁言回复于2022-04
#9那你去哪啦回复于2018-01

问一下win下的SDS怎么下载?

0
#8gentle丶G回复于2018-01

你好  win下的sdk怎么下载?下载怎么使用?

 

0
#7VBover回复于2018-01

找到错了,我下了一个并发的grequests模块,里面有从requests导入session,sdk也导入了,然后可能一直循环导入,报的错也是递归层数过多,我把两个导入位置换了一下就没问题了,但是还是不太清楚具体原理

0
#6用户已被禁言回复于2018-01
#5 VBover回复
[代码] 我把search那行后面全注释了仍然报错,就是用sdk调用api那行,后来我手写调用api仍然报的一样的错,ques是图片没有问题,昨天还能用,今天就不行了,是不是baidu的问题?
展开

因为我不是搞Python的。看不懂你的代码想做什么。用SDK调用通用OCR接口是没啥问题的。

可以和我的代码对比一下:

from aip import AipOcr
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
aipOcr =AipOcr(APP_ID,API_KEY,SECRET_KEY)
def get_file_content(filePath):
    with open(filePath,'rb') as fp:
        return fp.read()
image = get_file_content('G:/bank.jpg')  

result = aipOcr.basicGeneral(image,'');
print(result);

识别的结果:

{
    "log_id": 7781988560542400000, 
    "words_result_num": 11, 
    "words_result": [
        {
            "words": "招商银行"
        }
    ]
}
1
#5VBover回复于2018-01
#4 用户已被禁言回复
代码能完整吗?看你的那一行大概知道是SDK调用。Python SDK我也试过没问题呀。还很简单。
展开
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()


def get_results(num):
    ques = get_file_content('ques{}.png'.format(str(num)))
    answ = get_file_content('answ{}.png'.format(str(num)))
    search = client.basicGeneral(ques)
    answs = client.basicGeneral(answ)

    lstr = ""
    for i in search['words_result']:
        for _, v in i.items():
            lstr += v

    p = re.compile('\d*\.?(.+)')
    lstr = p.findall(lstr)[0]
    url = 'http://www.baidu.com/s?wd=' + lstr
    webbrowser.open(url)
    print(lstr)

    rlist = []
    for i in answs['words_result']:
        for _, v in i.items():
            rlist.append(v)
    analyse.get_answer(lstr, rlist)

我把search那行后面全注释了仍然报错,就是用sdk调用api那行,后来我手写调用api仍然报的一样的错,ques是图片没有问题,昨天还能用,今天就不行了,是不是baidu的问题?

0
#4用户已被禁言回复于2018-01
#3 VBover回复
  [代码] 这一行报错,是通用文字识别接口

代码能完整吗?看你的那一行大概知道是SDK调用。Python SDK我也试过没问题呀。还很简单。

0
#3VBover回复于2018-01

 

    search = client.basicGeneral(ques)

这一行报错,是通用文字识别接口

0
#2用户已被禁言回复于2018-01

你写的代码在哪?到底是SDK还是API调用?具体是哪个接口

1
TOP
切换版块