socket.gaierror: [Errno -2] Name or service not known
shi4712shi opened this issue · 3 comments
Hello! Looks to be a very useful tool. Following the "Installing BERN2" on READAME.md, I have installed BERN2 on my lab server. And I run the run_bern2.sh successfully with these logs:
[28/Mar/2022 10:13:16.373253] BERN2 LOADED..
* Serving Flask app 'app' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://**.***.**.*:8888/ (Press CTRL+C to quit)
but when I tried to use the bern2 API with
import requests
def query_plain(text, url=" http://**.***.**.*:8888/plain"):
return requests.post(url, json={'text': text}).json()
if __name__ == '__main__':
text = "Autophagy maintains tumour growth through circulating arginine."
print(query_plain(text))
the error occurred:
[28/Mar/2022 16:16:25.544316] id: cd11338c2ddb8a9c081e4083773b71ba8c2c25eb06698ac53af26704
Traceback (most recent call last):
File "PATH/TO/BERN2/bern2/bern2.py", line 106, in annotate_text
output = self.tag_entities(text, base_name)
File "PATH/TO/BERN2/bern2/bern2.py", line 358, in tag_entities
async_result = loop.run_until_complete(self.async_ner(arguments_for_coroutines))
File "PATH/TO/bern2/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete
return future.result()
File "PATH/TO/BERN2/bern2/bern2.py", line 491, in async_ner
result = await asyncio.gather(*coroutines)
File "PATH/TO/BERN2/bern2/bern2.py", line 517, in _ner_wrap
loop)
File "PATH/TO/BERN2/bern2/bern2.py", line 553, in async_tell_inputfile
sock.connect((host, port))
socket.gaierror: [Errno -2] Name or service not known
[2022-03-28 16:16:25,587] ERROR in app: Exception on /plain [POST]
Traceback (most recent call last):
File "PATH/TO/bern2/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app
response = self.full_dispatch_request()
File "PATH/TO/bern2/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request
rv = self.handle_user_exception(e)
File "PATH/TO/bern2/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request
rv = self.dispatch_request()
File "PATH/TO/bern2/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "PATH/TO/BERN2/app/__init__.py", line 85, in plain_api
return Response(json.dumps({"error_message": result_dict["error_message"]}), status=404, content_type='application/json')
NameError: name 'Response' is not defined
Thank you
(I'm not the root of the lab server, I remove the 'sudo' command in run_bern2.sh. But I'm not sure the effect.)
Hi @shi4712shi
Thanks for reaching out!
Actually, I've never come across similar errors, but you need to make sure that all modules including BERN2 are running on localhost.
According to this post, it seems like that the error log is related to /etc/hosts
.
Hi @mjeensung :
Thanks for your reply!
Yes, I run all modules on localhost and got the error. When I changed the host of the modules running on localhost from "localhost" to server IP, the error disappeared. So It seemed that my server failed to understand "localhost". Following the post you recommended, I added "localhost my_server_ip" to the "/etc/hosts" file, it also worked.
But a similar error with FileNotFoundError: [Errno 2] for local server POST occurred and I got the same log.
Thanks for your help!