materialsintelligence / matscholar

Code to access the Matscholar public API.
https://matscholar.com
MIT License
61 stars 19 forks source link

Connection to NERSC? #62

Open OlgaGKononova opened 4 years ago

OlgaGKononova commented 4 years ago

Hi all. I tried to play around with entities tagging and for the example given in the README I got the following:

(NERenv) olga@landau:~/PycharmProjects/Material_Coating$ python3.6 ner_trial.py 
Traceback (most recent call last):
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 376, in _make_request
    self._validate_conn(conn)
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
    conn.connect()
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/site-packages/urllib3/connection.py", line 420, in connect
    _match_hostname(cert, self.assert_hostname or server_hostname)
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/site-packages/urllib3/connection.py", line 430, in _match_hostname
    match_hostname(cert, asserted_hostname)
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/ssl.py", line 327, in match_hostname
    % (hostname, ', '.join(map(repr, dnsnames))))
ssl.CertificateError: hostname 'api.matscholar.com' doesn't match either of '*.nersc.gov', 'nersc.gov'

I don't have an account at NERSC, but I used API provided by John.

mkhorton commented 4 years ago

Try setting the endpoint to be http instead of https:

export MATERIALS_SCHOLAR_ENDPOINT="http://api.matscholar.com"

(or set the corresponding endpoint keyword argument in the Rester object)

This is a certificate error because there hasn't been a certificate generated for the api.matscholar.com domain, only for the NERSC domains it's running on, so when it tries connecting via HTTPS you get an error.

mkhorton commented 4 years ago

And a note to whoever's administering this (@jdagdelen?), you can either ask Spin to install a certificate you generate onto their load balancer, or you can use a service like LetsEncrypt to generate a certificate for you on-the-fly. We've tried both -- Materials Project uses the former and works well but was more effort, smaller services I've worked on uses the latter but it's been a little buggy at times.

You might also want to change your endpoint to include /v1 or similar to give yourselves room to change the API if you want to make breaking changes in future.

OlgaGKononova commented 4 years ago

Thank you Matt. I guess, John has already addressed my comment outside of github: the NER tagger is not implemented in API yet.

jdagdelen commented 4 years ago

For the particular error you were receiving Matt was correct. We don't support https right now, but that will change in the near future. My understanding is you wanted to use our API for entity tagging/labeling but now I'm thinking you just want to do NER on your own text. Is that the case?

OlgaGKononova commented 4 years ago

@mkhorton @jdagdelen Thank you guys for response. Problem still persists:

Traceback (most recent call last):
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/site-packages/matscholar/rest.py", line 83, in _make_request
    raise MatScholarRestError(response)
matscholar.rest.MatScholarRestError: <Response [422]>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "ner_trial.py", line 8, in <module>
    tagged_docs = rester.get_ner_tags(docs)
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/site-packages/matscholar/rest.py", line 323, in get_ner_tags
    return self._make_request(sub_url, payload=payload, method=method)
  File "/home/olga/anaconda3/envs/NERenv/lib/python3.6/site-packages/matscholar/rest.py", line 88, in _make_request
    raise MatScholarRestError(msg)
matscholar.rest.MatScholarRestError: <Response [422]>. Content: b'{"detail":[{"loc":["body","document"],"msg":"str type expected","type":"type_error.str"}]}'