rowansci / rowan-python

python API for rowan
https://docs.rowansci.com
MIT License
5 stars 0 forks source link

Rowan API Authentication 405 Error #5

Closed kangmg closed 1 month ago

kangmg commented 2 months ago

Dear rowan developers,

I am currently working on a simple project using the Rowan API. I've encountered an issue during basic API testing and would like to request your assistance.

Error detail

  {
      "detail": "Could not validate credentials"
  }

API test code

import rowan
import cctk
from private import ROWAN_API

# config API KEY
rowan.api_key = ROWAN_API # rowan api key

# client
client = rowan.Client(
    blocking=True,
    print=True
)

# calculation
result = client.compute(
    type="calculation",
    input_smiles="CC(=O)OC",
    name="test",
    method="gfn_ff",
    tasks=["energy"]
)

print(result)
---------------------------------------------------------------------------
HTTPStatusError                           Traceback (most recent call last)
Cell In[2], [line 14](vscode-notebook-cell:?execution_count=2&line=14)
      [8](vscode-notebook-cell:?execution_count=2&line=8) # client
      [9](vscode-notebook-cell:?execution_count=2&line=9) client = rowan.Client(
     [10](vscode-notebook-cell:?execution_count=2&line=10)     blocking=True,
     [11](vscode-notebook-cell:?execution_count=2&line=11)     print=True
     [12](vscode-notebook-cell:?execution_count=2&line=12) )
---> [14](vscode-notebook-cell:?execution_count=2&line=14) result = client.compute(
     [15](vscode-notebook-cell:?execution_count=2&line=15)     type="calculation",
     [16](vscode-notebook-cell:?execution_count=2&line=16)     input_smiles="CC(=O)OC",
     [17](vscode-notebook-cell:?execution_count=2&line=17)     name="test",
     [18](vscode-notebook-cell:?execution_count=2&line=18)     method="gfn_ff",
     [19](vscode-notebook-cell:?execution_count=2&line=19)     tasks=["energy"]
     [20](vscode-notebook-cell:?execution_count=2&line=20) )
     [22](vscode-notebook-cell:?execution_count=2&line=22) print(result)

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\rowan\client.py:75, in Client.compute(self, type, input_mol, input_smiles, name, folder_uuid, engine, **options)
     [62](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:62) else:
     [63](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:63)     response = client.post(
     [64](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:64)         f"{API_URL}/workflow",
     [65](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:65)         headers=self.headers,
   (...)
     [72](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:72)         },
     [73](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:73)     )
---> [75](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:75) response.raise_for_status()
     [76](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:76) response_dict = response.json()
     [77](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/rowan/client.py:77) calc_uuid = response_dict["uuid"]

File ~\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\httpx\_models.py:761, in Response.raise_for_status(self)
    [759](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/httpx/_models.py:759) error_type = error_types.get(status_class, "Invalid status code")
    [760](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/httpx/_models.py:760) message = message.format(self, error_type=error_type)
--> [761](https://file+.vscode-resource.vscode-cdn.net/c%3A/Users/Master/compchem/project/rowan/~/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0/LocalCache/local-packages/Python311/site-packages/httpx/_models.py:761) raise HTTPStatusError(message, request=request, response=self)

HTTPStatusError: Client error '405 Method Not Allowed' for url 'https://api.rowansci.com/calculation'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
corinwagen commented 2 months ago

Just reproduced this locally - whoops! We recently completed a big refactor and forgot to sync the API updates for rowan-python - that's on us for not having CI/CD properly set up here yet.

I'll get this fixed and re-release rowan-python in a few days. Note that only type="calculation" should be malfunctioning, and everything else should work fine. I've tested a few workflows just now - here's an example:

import rowan

rowan.api_key = "rowan-skyoursecretkeyhere"
client = rowan.Client(blocking=True)

result = client.compute(
    "pka",
    input_smiles="c1ccccn1",
    name="pyridine pka",
    mode="careful",
    pka_range=(0, 14),
    deprotonate_elements=[7, 8, 16],
    protonate_elements=[7]
)

print(result)
corinwagen commented 1 month ago

Hey @kangmg sorry for the delay - we ended up completely rewriting our entire API :/

We've released v1.0.0 on pypi and the new documentation is here. Here's a working example for the new API:

import rowan
from private import ROWAN_API

rowan.api_key = ROWAN_API

folder = rowan.Folder.create(
    name="test Rowan API folder"
)

result = rowan.compute(
    workflow_type="basic_calculation",
    molecule="CC(=O)OC",
    name="test",
    settings={"method": "gfn_ff", "tasks": ["energy"]},
    engine="xtb",
)

print(result)

I hope this helps, and please reach out again if you have more issues!

kangmg commented 1 month ago

Sorry for the late response. I tested it today, and it worked fine in my local environment!

However, when I tried it in a colab environment, an error occurred.

[/usr/local/lib/python3.10/dist-packages/rowan/workflow.py](https://localhost:8080/#) in Workflow()
     14         workflow_data: dict,
     15         name: Optional[str] = None,
---> 16         folder_uuid: Optional[stjames.UUID] = None,
     17     ) -> dict:
     18         if isinstance(initial_molecule, stjames.Molecule):

AttributeError: module 'stjames' has no attribute 'UUID'

It seems that rowan-python==1.0.0 requires stjames = ">=0.0.42", which in turn requires Python 3.11 or higher. However, rowan-python==1.0.0 is set with requires-python = ">=3.8". This means it can be installed on Python 3.10 or lower, but version dependency issues can lead to errors.

Thank you for your excellent service :)