IHTSDO / snowstorm

Scalable SNOMED CT Terminology Server using Elasticsearch
Other
204 stars 80 forks source link

Access Denied to SNOMED CT #539

Closed all4ferrari closed 1 year ago

all4ferrari commented 1 year ago

I am trying to use the following Python connection to SNOMED: https://github.com/IHTSDO/SNOMED-in-5-minutes/blob/master/python3-examples/examples.py

but regardless of how I change/update the code, I always get the same error: HTTPError: HTTP Error 423:

after trying it out in swagger (which by the way doesnt deny access), I have updated the url to this: 'url = 'https://browser.ihtsdotools.org/snowstorm/snomed-ct/browser/MAIN/SNOMEDCT-US/2023-03-01//concepts/182548004''

the swagger API returns success code 200: curl -X 'GET' \ 'https://browser.ihtsdotools.org/snowstorm/snomed-ct/browser/MAIN%2FSNOMEDCT-US%2F2023-03-01/concepts?conceptIds=182548004&number=0&size=100' \ -H 'accept: application/json' \ -H 'Accept-Language: en-X-900000000000509007,en-X-900000000000508004,en'

and I do receive the required info by using the swagger: { "items": [ { "conceptId": "182548004", "fsn": { "term": "Chiropraxy (regime/therapy)", "lang": "en" }, "pt": { "term": "Chiropraxy", "lang": "en" }]}

can someone help me make it work via python as well?

this is the latest edition of my code:

# import libraries
from urllib.request import urlopen, Request
from urllib.parse import quote
import json

baseUrl = 'https://browser.ihtsdotools.org/snowstorm/snomed-ct'
edition = 'MAIN'
version = '2023-07-31'
branch = 'MAIN/SNOMEDCT-US/2023-03-01'

url = 'https://browser.ihtsdotools.org/snowstorm/snomed-ct/browser/MAIN/SNOMEDCT-US/2023-03-01//concepts/182548004'

req = Request(url)
req.add_header('User-Agent','Python3') # this is from the 5-minute tutorial
req.add_header('accept','application/json') # this I added in order to be exactly like in the API request
req.add_header('Accept-Language','en-X-900000000000509007,en-X-900000000000508004,en') # this I added in order to match the API request
urlopen(req)

response = urlopen(req).read()
data = json.loads(response.decode('utf-8'))
print (data['fsn']['term'])

the response is an error: ----> 8 urlopen(req) HTTPError: HTTP Error 423:

kaicode commented 1 year ago

The 'Python3' user agent is currently banned from accessing the public server because there have been many abuse attacks using that. If you keep the Python3 part but also add your email address to the user agent it should start working. That way we can uniquely identify your Python scripts and contact you if there is ever any service issue related to the requests you are making.


This behaviour has changed. Now it is necessary to replace the "Python" part with your email address in the user-agent header.

all4ferrari commented 1 year ago

thanks mate! I have changed Python3 to my e-mail address and I have access.