我在内网部署了一个PaddleOCR的服务,可以调用接口把图片转文字。另外,写了一个python脚本方便调用这个OCR接口。
我在iterm中执行类似如下命令:
python3 'xxx.py' 'yyy.png' --ocr-service 'paddle' --language ''
可以成功返回’yyy.png’的ocr结果。
但是在emacs,如果把上述代码放进 #+begin_src bash
中,就不能成功执行。
如果我启用了ssr,会报错
Traceback (most recent call last):
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 1347, in getresponse
response.begin()
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 276, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 637, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/util/retry.py", line 368, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 1347, in getresponse
response.begin()
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 276, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yuchen/Works/personal/pdfhelper/picture_handler.py", line 154, in <module>
main(args)
File "/Users/yuchen/Works/personal/pdfhelper/picture_handler.py", line 136, in main
ocr_result = Picture(path).get_ocr_result(
File "/Users/yuchen/Works/personal/pdfhelper/picture_handler.py", line 22, in get_ocr_result
ocr_result = ocr.get_ocr_result(language)
File "/Users/yuchen/Works/personal/pdfhelper/picture_handler.py", line 56, in get_ocr_result_by_paddle
res = requests.post(
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/sessions.py", line 524, in request
resp = self.send(prep, **send_kwargs)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/sessions.py", line 637, in send
r = adapter.send(request, **kwargs)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/adapters.py", line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
如果我关闭了ssr,会报错
Traceback (most recent call last):
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connection.py", line 158, in _new_conn
conn = connection.create_connection(
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/util/connection.py", line 80, in create_connection
raise err
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/util/connection.py", line 70, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 597, in urlopen
httplib_response = self._make_request(conn, method, url,
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 1255, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 1301, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 1250, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 1010, in _send_output
self.send(msg)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/http/client.py", line 950, in send
self.connect()
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connection.py", line 181, in connect
conn = self._new_conn()
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connection.py", line 167, in _new_conn
raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x10702ca90>: Failed to establish a new connection: [Errno 61] Connection refused
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/connectionpool.py", line 637, in urlopen
retries = retries.increment(method, url, error=e, _pool=self,
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='10.0.0.12', port=8866): Max retries exceeded with url: /predict/chinese_ocr_db_crnn_mobile (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10702ca90>: Failed to establish a new connection: [Errno 61] Connection refused'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/yuchen/Works/personal/pdfhelper/picture_handler.py", line 154, in <module>
main(args)
File "/Users/yuchen/Works/personal/pdfhelper/picture_handler.py", line 136, in main
ocr_result = Picture(path).get_ocr_result(
File "/Users/yuchen/Works/personal/pdfhelper/picture_handler.py", line 22, in get_ocr_result
ocr_result = ocr.get_ocr_result(language)
File "/Users/yuchen/Works/personal/pdfhelper/picture_handler.py", line 56, in get_ocr_result_by_paddle
res = requests.post(
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/sessions.py", line 524, in request
resp = self.send(prep, **send_kwargs)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/sessions.py", line 637, in send
r = adapter.send(request, **kwargs)
File "/Users/yuchen/.pyenv/versions/3.8.6/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='10.0.0.12', port=8866): Max retries exceeded with url: /predict/chinese_ocr_db_crnn_mobile (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x10702ca90>: Failed to establish a new connection: [Errno 61] Connection refused'))
感觉像是运行环境的问题,所以做了如下检查:
- iterm用的zsh,在emacs中用zsh执行命令依然报错
- 我用的doom-emacs,查看env文件,里面有设置
NO_PROXY=10.0.0.12,localhost
和SHELL=/bin/zsh
- emacs和iterm用的python3版本一致
还是没找到问题,恳请指教!