I am having a big issue involving the socket in the first few lines in the "simple usage" example:
from stanfordcorenlp import StanfordCoreNLP
nlp = StanfordCoreNLP(r'/Users/georgestoica/Desktop/stanford-corenlp-full-2018-10-05')
sentence = 'Guangdong University of Foreign Studies is located in Guangzhou.'
print('Tokenize: {}'.format(nlp.word_tokenize(sentence)))
Problem:
(I have to run with sudo because otherwise I get psutils issues as in #26) When I run the python script containing the above 4 lines I receive the following error:
Traceback (most recent call last):
File "/Users/georgestoica/Library/Preferences/PyCharm2019.1/scratches/scratch_57.py", line 3, in <module> <-- "This is the nlp = StanfordCoreNLP(...)"
nlp = StanfordCoreNLP(r'/Users/georgestoica/Desktop/stanford-corenlp-full-2018-10-05')
File "/opt/anaconda3/lib/python3.7/site-packages/stanfordcorenlp/corenlp.py", line 119, in __init__
while sock.connect_ex((host_name, self.port)):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Based on my searches online, people have suggested solutions involving getting the hostname from the socket package. I've tried this by changing line 114 in corenlp.py
host_name = urlparse(self.url).hostname
to
host_name = socket.gethostbyname('MacBook-Pro-10.local')
or
host_name = socket.gethostname()
Interestingly, these replacements allow the "nlp = StanfordCoreNLP(...)" line to pass. However, as soon as the script reaches line 6:
It throws the following error of not being able to connect to the server:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site-packages/urllib3/connection.py", line 159, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw)
File "/opt/anaconda3/lib/python3.7/site-packages/urllib3/util/connection.py", line 57, in create_connection
for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
File "/opt/anaconda3/lib/python3.7/socket.py", line 748, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/opt/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 354, in _make_request
conn.request(method, url, **httplib_request_kw)
File "/opt/anaconda3/lib/python3.7/http/client.py", line 1244, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/opt/anaconda3/lib/python3.7/http/client.py", line 1290, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "/opt/anaconda3/lib/python3.7/http/client.py", line 1239, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "/opt/anaconda3/lib/python3.7/http/client.py", line 1026, in _send_output
self.send(msg)
File "/opt/anaconda3/lib/python3.7/http/client.py", line 966, in send
self.connect()
File "/opt/anaconda3/lib/python3.7/site-packages/urllib3/connection.py", line 181, in connect
conn = self._new_conn()
File "/opt/anaconda3/lib/python3.7/site-packages/urllib3/connection.py", line 168, in _new_conn
self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 0x7fd948217dd0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/opt/anaconda3/lib/python3.7/site-packages/urllib3/connectionpool.py", line 638, in urlopen
_stacktrace=sys.exc_info()[2])
File "/opt/anaconda3/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=9010): Max retries exceeded with url: /?properties=%7B%27annotators%27%3A+%27ssplit%2Ctokenize%27%2C+%27outputFormat%27%3A+%27json%27%7D&pipelineLanguage=en (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd948217dd0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/georgestoica/Library/Preferences/PyCharm2019.1/scratches/scratch_57.py", line 6, in <module>
print(nlp.word_tokenize(sentence))
File "/opt/anaconda3/lib/python3.7/site-packages/stanfordcorenlp/corenlp.py", line 178, in word_tokenize
r_dict = self._request('ssplit,tokenize', sentence)
File "/opt/anaconda3/lib/python3.7/site-packages/stanfordcorenlp/corenlp.py", line 243, in _request
r = requests.post(self.url, params=params, data=data, headers={'Connection': 'close'})
File "/opt/anaconda3/lib/python3.7/site-packages/requests/api.py", line 116, in post
return request('post', url, data=data, json=json, **kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/opt/anaconda3/lib/python3.7/site-packages/requests/adapters.py", line 516, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9010): Max retries exceeded with url: /?properties=%7B%27annotators%27%3A+%27ssplit%2Ctokenize%27%2C+%27outputFormat%27%3A+%27json%27%7D&pipelineLanguage=en (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fd948217dd0>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known'))
I've searched if people have had similar problems, but haven't been able to find anything very usable.
System:
OSX 10.14.6
(anaconda 3) python 3.7.4
Any help or suggestions would be greatly appreciated!
Thanks!
Hi,
I am having a big issue involving the socket in the first few lines in the "simple usage" example:
Problem: (I have to run with sudo because otherwise I get psutils issues as in #26) When I run the python script containing the above 4 lines I receive the following error:
Based on my searches online, people have suggested solutions involving getting the hostname from the socket package. I've tried this by changing line 114 in corenlp.py
to
host_name = socket.gethostbyname('MacBook-Pro-10.local')
orhost_name = socket.gethostname()
Interestingly, these replacements allow the "nlp = StanfordCoreNLP(...)" line to pass. However, as soon as the script reaches line 6:
It throws the following error of not being able to connect to the server:
I've searched if people have had similar problems, but haven't been able to find anything very usable.
System: OSX 10.14.6 (anaconda 3) python 3.7.4
Any help or suggestions would be greatly appreciated! Thanks!