nleroy917 / optipyzer

Multi-Species Codon Optimization Engine
https://optipyzer.com
Apache License 2.0
25 stars 6 forks source link

Local server run time error #54

Closed khuang314 closed 1 year ago

khuang314 commented 1 year ago

Hi,

I git an error when I was trying the sample code in the README file. Can you please take a look where the problem may come from? Thanks

This is my script:

import optipyzer
api = optipyzer.API(local=True) # <--- specify you are using a local server
dna_seq = "ATGGCCCTTTAA"
result = api.optimize(
        seq=dna_seq,
        seq_type="dna",
        weights={"human": 2, "mouse": 1},
    )

print(result['optimized_sd'])

Here is the message on the script side:

$./codon_optimizer.py

ERROR - Request failed with status code: 500 Traceback (most recent call last): File "/home/kh/software/anaconda3/envs/optipyzer/lib/python3.9/site-packages/requests/models.py", line 971, in json return complexjson.loads(self.text, **kwargs) File "/home/kh/software/anaconda3/envs/optipyzer/lib/python3.9/json/init.py", line 346, in loads return _default_decoder.decode(s) File "/home/kh/software/anaconda3/envs/optipyzer/lib/python3.9/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/home/kh/software/anaconda3/envs/optipyzer/lib/python3.9/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/mnt/raid0/kh/data/tmp/./codon_optimizer.py", line 9, in result = api.optimize( File "/home/kh/software/anaconda3/envs/optipyzer/lib/python3.9/site-packages/optipyzer/api.py", line 161, in optimize result = self._make_request( File "/home/kh/software/anaconda3/envs/optipyzer/lib/python3.9/site-packages/optipyzer/api.py", line 82, in _make_request _LOGGER.error(f"{response.json()}") File "/home/kh/software/anaconda3/envs/optipyzer/lib/python3.9/site-packages/requests/models.py", line 975, in json raise RequestsJSONDecodeError(e.msg, e.doc, e.pos) requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Here is the message from the Docker side: $ docker run -p 8000:8000 optipyzer

/usr/local/lib/python3.9/site-packages/pydantic/_internal/_config.py:269: UserWarning: Valid config keys have changed in V2:

  • 'schema_extra' has been renamed to 'json_schema_extra' warnings.warn(message, UserWarning) /usr/local/lib/python3.9/site-packages/pydantic/_internal/_config.py:269: UserWarning: Valid config keys have changed in V2:
  • 'orm_mode' has been renamed to 'from_attributes' warnings.warn(message, UserWarning) INFO: Started server process [1] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) INFO: 172.17.0.1:56260 - "POST /optimize/protein HTTP/1.1" 500 Internal Server Error ERROR: Exception in ASGI application Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/uvicorn/protocols/http/httptools_impl.py", line 436, in run_asgi result = await app( # type: ignore[func-returns-value] File "/usr/local/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in call return await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/fastapi/applications.py", line 292, in call await super().call(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/applications.py", line 122, in call await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 184, in call raise exc File "/usr/local/lib/python3.9/site-packages/starlette/middleware/errors.py", line 162, in call await self.app(scope, receive, _send) File "/usr/local/lib/python3.9/site-packages/starlette/middleware/cors.py", line 83, in call await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 79, in call raise exc File "/usr/local/lib/python3.9/site-packages/starlette/middleware/exceptions.py", line 68, in call await self.app(scope, receive, sender) File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in call raise e File "/usr/local/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in call await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 718, in call await route.handle(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 276, in handle await self.app(scope, receive, send) File "/usr/local/lib/python3.9/site-packages/starlette/routing.py", line 66, in app response = await func(request) File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 291, in app content = await serialize_response( File "/usr/local/lib/python3.9/site-packages/fastapi/routing.py", line 154, in serialize_response raise ResponseValidationError( fastapi.exceptions.ResponseValidationError: 6 validation errors: {'type': 'string_type', 'loc': ('response', 'weights', 122563, '[key]'), 'msg': 'Input should be a valid string', 'input': 122563, 'url': 'https://errors.pydantic.dev/2.3/v/string_type'} {'type': 'string_type', 'loc': ('response', 'weights', 122638, '[key]'), 'msg': 'Input should be a valid string', 'input': 122638, 'url': 'https://errors.pydantic.dev/2.3/v/string_type'} {'type': 'string_type', 'loc': ('response', 'best_expression_sd', 122563, '[key]'), 'msg': 'Input should be a valid string', 'input': 122563, 'url': 'https://errors.pydantic.dev/2.3/v/string_type'} {'type': 'string_type', 'loc': ('response', 'best_expression_sd', 122638, '[key]'), 'msg': 'Input should be a valid string', 'input': 122638, 'url': 'https://errors.pydantic.dev/2.3/v/string_type'} {'type': 'string_type', 'loc': ('response', 'best_expression_ad', 122563, '[key]'), 'msg': 'Input should be a valid string', 'input': 122563, 'url': 'https://errors.pydantic.dev/2.3/v/string_type'} {'type': 'string_type', 'loc': ('response', 'best_expression_ad', 122638, '[key]'), 'msg': 'Input should be a valid string', 'input': 122638, 'url': 'https://errors.pydantic.dev/2.3/v/string_type'}`
nleroy917 commented 1 year ago

hey @AntibodyDiscovery

thank you for this issue! Can you confirm the python version? It looks like python 3.9. I appreciate the reproducible script. I'll be able to take a look at this tomorrow and get back to you.

khuang314 commented 1 year ago

Thanks, @nleroy917 My python version in 3.9.17 : $ python

Python 3.9.17 (main, Jul 5 2023, 20:41:20) [GCC 11.2.0] :: Anaconda, Inc. on linux

And OS: $ lsb_release -a

No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 22.04.2 LTS Release: 22.04 Codename: jammy

nleroy917 commented 1 year ago

Hi @AntibodyDiscovery

I finally got some time to track this down. It was a pydantic thing I believe when they changed to 2.0. Would you try again and let me know if it works for you?

khuang314 commented 1 year ago

Hi @nleroy917

The v0.2.2 works perfectly. Thank you so much for the help. Cheers!

nleroy917 commented 1 year ago

Fantastic. Glad that fixed your issue! Let me know if you have any other issues.