Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mpds_client/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class APIError(Exception):
429: "Too Many Requests (Rate Limiting)",
500: "Internal Server Error",
501: "Not Implemented",
502: "Bad Gateway",
503: "Service Unavailable",
}

Expand Down
18 changes: 7 additions & 11 deletions mpds_client/retrieve_MPDS.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import warnings
from urllib.parse import urlencode

import httplib2
import requests
import ujson as json
import polars as pl
from numpy import array_split
import jmespath

from errors import APIError
from .errors import APIError

use_pmg, use_ase = False, False

Expand Down Expand Up @@ -127,8 +127,6 @@ def __init__(
"""
self.api_key = api_key if api_key else os.environ["MPDS_KEY"]

self.network = httplib2.Http()

self.endpoint = endpoint or self.endpoint
self.dtype = dtype or MPDSDataTypes.PEER_REVIEWED
self.verbose = verbose if verbose is not None else self.verbose
Expand All @@ -154,16 +152,14 @@ def _request(self, query, phases=None, page=0, pagesize=None):
if self.debug:
print('curl -XGET -HKey:%s "%s"' % (self.api_key, uri))

response, content = self.network.request(
uri=uri, method="GET", headers={"Key": self.api_key}
)
response = requests.get(uri, headers={"Key": self.api_key})

if response.status != 200:
return {"error": content, "code": response.status}
if response.status_code != 200:
return {"error": response.text, "code": response.status_code}

try:
content = json.loads(content)
except:
content = json.loads(response.text)
except ValueError:
return {"error": "Unreadable data obtained"}

if content.get("error"):
Expand Down
2 changes: 1 addition & 1 deletion mpds_client/test_export_MPDS.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest
import os
import polars as pl
from export_MPDS import MPDSExport
from .export_MPDS import MPDSExport


class TestMPDSExport(unittest.TestCase):
Expand Down
14 changes: 5 additions & 9 deletions mpds_client/test_retrieve_MPDS.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

import polars as pl

import httplib2
import ujson as json
import requests
from jsonschema import validate, Draft4Validator
from jsonschema.exceptions import ValidationError

from retrieve_MPDS import MPDSDataRetrieval
from .retrieve_MPDS import MPDSDataRetrieval
import logging


Expand All @@ -17,13 +16,10 @@ class MPDSDataRetrievalTest(unittest.TestCase):
def setUpClass(cls):
# warnings.filterwarnings("ignore", category=ResourceWarning, message="unclosed.*<ssl.SSLSocket.*>")

network = httplib2.Http()
response, content = network.request(
"https://developer.mpds.io/mpds.schema.json"
)
assert response.status == 200
response = requests.get("https://developer.mpds.io/mpds.schema.json")
assert response.status_code == 200

cls.schema = json.loads(content)
cls.schema = response.json()
Draft4Validator.check_schema(cls.schema)

def test_valid_answer(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from setuptools import setup

install_requires = [
'httplib2',
'requests',
'ujson',
'numpy',
'polars',
Expand Down